整型包装类值的比较 所有整型包装类对象值的比较必须使用equals方法。 先看下面这个例子: Integer x = 3; Integer y = 3; System.out.println(x == y);// true Integer a = new Integer(3); Integer b = new Integer(3); System.out.println(a == b);//false System.out.println(a.equals(b));//true 当使用自动装箱方式创建一个Integer对象时,当数值在-128 ~127时,会将创建的 Integer 对象缓存起来,当下次再出现该数值时,直接从缓存中取出对应的Integer对象。所以上述代码中,x和y引用的是相同的Integer对象。

相关推荐

allin实习的大白...:我把第二个项目发出来了,如果感兴趣可以去研究研究,欢迎交流。 https://gitee.com/jtyjtyjty333/ind-dist-ai-sec-edge-cloud https://github.com/jtylab/ind-dist-ai-sec-edge-cloud
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务