常量池(1)

package constantPool;
//1.基本类型对包装类(除Float,Double外),比如Boolean,Byte,Short,Integer,Long,Character都有常量池
//2.String类也有常量池
public class Pools {
    
    
	public static void main(String[] args) {
    
    
		System.out.println("Boolean测试");
		Boolean b1 = true;
		Boolean b2 = true;
		System.out.println(b1==b2);
		
		System.out.println("Byte测试");
		Byte by1 = 127;
		Byte by2 = 127;
		System.out.println(by1==by2);
		
		System.out.println("Character测试");
		Character ch1 = 127;
		Character ch2 = 127;
		System.out.println(ch1==ch2);
		
		Character ch3 = 128;
		Character ch4 = 128;
		System.out.println(ch3==ch4);
		
		System.out.println("Double测试");
		Double d1 = 127D;
		Double d2 = 127D;
		System.out.println(d1==d2);
		
		System.out.println("String测试");
		String s1 = "abc";
		String s2 = "abc";
		String s3 = "a"+"b"+"c";
		System.out.println(s1==s2);
		System.out.println(s1==s3);
		//其他对痘差不多......Integer,Long,Short,Byte只在 -128~127之间生效
		//(Byet只能表示-128~127之间对数,超过128会报错),Character在0~127之间生效
		//Boolean在true,false之间生效
		//String暂时不清楚
	}
}

结果:
在这里插入图片描述
说明:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Aurora____/article/details/107719291