两个Integer的比较问题

两个不同的Integet是不能比较的

Interger a=1和Interger b=1是不相等的。因为虽然他们值相等但是在内存中的地址是不同的。

另外遇见的一个相关的问题

List<Integer> mulList=new ArrayList<>();

mulList.add(1);
 mulList.add(1);

 Integer max = Collections.max(mulList); 

mulList.get(1)==max;     (1)

mulList.get(2)==max;     (2)

在1和2的比较中 ,(1)是相等的,(2)是不相等的

因为 Integer max = Collections.max(mulList);返回的是mulList.get(1)的对象,所以他们是相等的

另外一个是不相等的。

posted @ 2019-03-05 15:51  远方的人111  阅读(267)  评论(0)    收藏  举报