String
作者:互联网
用intern();方法在test和main中结果不一样,很离奇
@Test public void test10(){ String s = new String("1"); s.intern(); String s2 = "1"; System.out.println(s == s2); String s3 = new String("1") + new String("1"); s3.intern(); String s4 = "11"; System.out.println(s3 == s4); //false }
public static void main(String[] args) { String s = new String("1"); s.intern(); String s2 = "1"; System.out.println(s == s2); String s3 = new String("1") + new String("1"); s3.intern(); String s4 = "11"; System.out.println(s3 == s4); //true }
标签:String,s3,System,intern,new,out 来源: https://www.cnblogs.com/LLFA/p/16536406.html