String常量池问题的几个例子 示例1: Java代码 String s0="kvill"; String s1="kvill"; String s2="kv" + "ill"; System.out.println( s0==s1 ); System.out.println( s0==s2 ); 结果为: true true 示例2: 示例: Java代码 String s0="kvill"; String s1=new String("kvill"); String s2="kv" + new String("ill"); System.out.println( s0==s1 ); System.out.println( s0==s2 ); System.out.println( s1==s2 ); 结果为: false false false 示例3: Java代码 String a = "a1"; String b = "a" + 1; System.out.println((a == b)); //result = true String a = "atrue"; String b = "a" + "true"; System.out.println((a == b)); //result = true String a = "a3.4"; String b = "a" + 3.4; System.out.println((a == b)); //result = true 示例4: Java代码 String a = "ab"; String bb = "b"; String b = "a" + bb; System.out.println((a == b)); //result = false 示例5: Java代码 String a = "ab"; final String bb = "b"; String b = "a" + bb; System.out.println((a == b)); //result = true 示例6: Java代码 String a = "ab"; final String bb = getBB(); String b = "a" + bb; System.out.println((a == b)); //result = false private static String getBB() { return "b"; }