public class Test {
public static void main(String[] args) {
String x = "1";
int y = 2;
int z = 3;
System.out.println(x+y+z);
}
}
当String对象进行"+"操作,编译时会将String类变为StringBuilder进行append( )处理,而append( )方法的功能就是字符串拼接。且优先级相同从左到右计算。
public class Test {
public static void main(String[] args) {
String x = "1";
int y = 2;
int z = 3;
//System.out.println(x+y+z);
StringBuilder sb = new StringBuilder();
System.out.println(sb.append(x).append(y).append(z));
}
}