java字符串面试题

    public static void main(String[] args) {
        String s1 = "abcd";
        String s2 = new String("abcd");
        System.out.println(s2.intern() == s1);
        String s3 = "ab";
        String s4 = "cd";
        String s5 = s3 + s4;
        final String s6 = s3 + s4;
        System.out.println("s5 == s6 :" +(s5 == s6));
        System.out.println("s1 == s6 :" +(s1 == s6));
        System.out.println(s1 == s2);
        System.out.println(s1.equals(s2));
    }

  有时间研究一下

转载于:https://www.cnblogs.com/leodaxin/p/8721349.html

你可能感兴趣的:(java字符串面试题)