public static void main(String[] s){
String a1 = new String("hello ");
System.out.println("第一个a1 = "+a1.hashCode());
a1 += "world";
System.out.println("第二个a1 = "+a1.hashCode());
StringBuffer a2 = new StringBuffer("hello ");
System.out.println("第一个a2 = "+a2.hashCode());
a2.append("world");
System.out.println("第二个a2 = "+a2.hashCode());
}
运行结果
第一个a1 = -1220935282
第二个a1 = 1794106052
第一个a2 = 2018699554
第二个a2 = 2018699554
查看jvm中String、StringBuffer的哈希码地址