下面是一段代码以及运行结果:请对结果给予解释publicclassStringAndStringBuffer{publicstaticvoidmain(String[]args){/*Strings1="a";Strings2="b";Strings3="ab";System.out.print...
下面是一段代码以及运行结果:请对结果给予解释
public class StringAndStringBuffer
{
public static void main(String [] args)
{
/*
String s1 = "a";
String s2 = "b";
String s3 = "ab";
System.out.println(s3 == s1 + s2);
System.out.println(s3 == "a" + "b");
*/
/*============================RESULT==============================
--------------------Configuration: --------------------
false
true
Process completed.
=================================================================*/
String s1 = "a";
String s2 = "b";
String s3 = "ab";
String s4 = s1 + s2;
String s5 = "a" + "b";
String s6 = s1 + "b";
StringBuffer s7 = new StringBuffer("abc");
String s8 = s7.substring(3);
System.out.println(s3 == s4);
System.out.println(s3 == s5);
System.out.println(s3 == s6);
System.out.println(s4 == s6);
System.out.println(s4 == s8);
/*=========================Result===============================
--------------------Configuration: --------------------
false
true
false
false
Process completed.
*/
}
}
展开