String的intern()方法和java关键字、保留字

时间:2024-08-28 20:07:02
          String s1 = new StringBuilder("hel").append("lo").toString();  //hello
          System.out.println(s1.intern() == s1);  //true

          String s2 = new StringBuilder("ja").append("va").toString();  //java---->???? java是关键字吗
          System.out.println(s2.intern() == s2);  //false

          String s3 = new StringBuilder("in").append("t").toString(); //int
          System.out.println(s3.intern() == s3);  //false

          String s4 = new StringBuilder("flo").append("at").toString(); //float
          System.out.println(s4.intern() == s4);  //false

          String s5 = new StringBuilder("def").append("ault").toString();  //default
          System.out.println(s5.intern() == s5);  //false

          String s6 = new StringBuilder("impl").append("ements").toString();  //implements ---->???? implements是关键字
          System.out.println(s6.intern() == s6);  //true

疑惑:常量池到底有哪些初始内容????

String的intern()方法和java关键字、保留字

上图截自java.lang.String

String的intern()方法和java关键字、保留字

上图截自百度百科