阅读背景:

Java中判断Integer类型的值是否相等_sinat_34241861的博客_java判断integer是否相等

来源:互联网 

例子

public class Demo {
	public static void main(String[] args) {
		Integer c = -128;
		Integer d = -128;
		System.out.println("c == d: " + (c == d));
		System.out.println("c.equals(d): " + c.equals(d));
		System.out.println("c.intValue() == d.intValue(): " + (c.intValue() == d.intValue()));
		System.out.println("Objects.equals(c, d): " + Objects.equals(c, d));
		
		Integer e = 127;
		Integer f = 127;
		System.out.println("e == f: " + (e == f));
		System.out.println("e.equals(f): " + e.equals(f));
		System.out.println("e.intValue() == f.intValue(): " + (e.intValue() == f.intValue()));
		System.out.println("Objects.equals(e, f): " + Objects.equals(e, f));
		
		Integer g = 128;
		Integer h = 128;
		System.out.println("g == h: " + (g == h));
		System.out.println("g.equals(h): " + g.equals(h));
		System.out.println("g.intValue() == h.intValue():" + (g.intValue() == h.intValue()));
		System.out.println("Objects.equals(g, h): " + Objects.equals(g, h));
	}
}
public class Demo {
	public static 



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: