Java String object instruction (二)

2014-11-24 10:53:14 · 作者: · 浏览: 1
()==str2.hashCode());

str1="xyz";

System.out.println(str1);

System.out.println(str2);

System.out.println(str1.hashCode());

System.out.println(str2.hashCode());

System.out.println(str1.equals(str2));

System.out.println(str1==str2);

System.out.println(str1.hashCode()==str2.hashCode());

}

Output:

abc

abc

96354

96354

true

true

true

xyz

abc

119193

96354

false

false

false

Differences between String and StringBuffer in Java

Main difference between String and StringBuffer is String is immutable while StringBuffer is mutable means tou can modify a StringBuffer object once you created it without creating any new object. This mutable property makes StringBuffer an ideal choice for dealing with Strings in Java. You can convert a StringBuffer into String by its toString() method.