String str = new String("SOME")总是在堆上创建一个新对象
String str="SOME"
使用字符串池
试试这个小例子:
String s1 = new String("hello"); String s2 = "hello"; String s3 = "hello"; System.err.println(s1 == s2); System.err.println(s2 == s3);为避免在堆上创建不必要的对象,请使用第二种形式。



