java 常量池

2018-01-06  本文已影响0人  安安zoe

1. 什么是常量池

2. 为什么需要常量池

3. String类与常量池

        String s1 = "abcdefg";
        String s2 = "abc"+"defg";
        String s3 = new String("abcdefg");
        String s4 = s2;
        String ss ="defg";
        String s5 = "abc"+ss;
        System.out.println(s1 == s2); //true
        System.out.println(s1 == s3); //false
        System.out.println(s1 == s4); //ture
        System.out.println(s1 == s5); //false

4. 基本类型包装类与常量池

        Integer i1 = 10;
        Integer i2 = 10;
        Integer i3 = 300;
        Integer i4 = 300;
        System.out.println(i1==i2); // true
        System.out.println(i3 ==i4);// false
        int i =40;
        Integer i5 = new Integer(40);
        System.out.println(i==i5);//true

参考

上一篇 下一篇

猜你喜欢

热点阅读