String
字符串变量相加,先开辟空间,再相加;
字符串常量相加,首先在字符串常量池中找,有没有当前这个常量值,有,就直接返回,没有需要创建
public class StringDemo {
public static void main(String[] args) {
String s1 = "Hello";
String s2 = "world";
String s3 = "Helloworld";
System.out.println(s3 == s1 + s2);
System.out.println(s3.equals(s1 + s2));
System.out.println(s3 == "Hello" + "world");
System.out.println(s3.equals("Hello" + "world"));
}
}