java中Integer比较需要注意的问题

package com.srie.test;

import java.util.HashMap;
import java.util.Map; public class Test003 {
public static void main(String[] args) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("i1", new Integer(1));
map.put("i2", new Integer(1));
Integer i1 = new Integer(1);
Integer i2 = new Integer(1);
Integer i3 = new Integer(2);
System.out.println(i1.compareTo(i2));
if(i3>=i1){
System.out.println("i3>i1");
}else{
System.out.println("i3<=i1");
}
if (i1 == i2) {
System.out.println("i1==i2");
} else {
System.out.println("i1!=i2");
}
Integer i1O = (Integer) map.get("i1");
Integer i2O = (Integer) map.get("i2");
if (i1O == i2O) {
System.out.println("i1O==i2O");
} else {
System.out.println("i1O!=i2O");
} }
}

使用List进行是否包含的判断情况:

public class Test006 {
public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
list.add(1); Integer i1 = new Integer(1);
Integer i2 = new Integer(1);
System.out.println(i1==i2); // false
System.out.println(list.contains(i1)); // true
System.out.println(list.contains(i2)); // true
}
}

java中Integer比较需要注意的问题的更多相关文章

  1. java中Integer 和String 之间的转换

    java中Integer 和String 之间的转换 将数组转换成字符串:char[] array = {'a','b','c','d','e'};String str = new String(ar ...

  2. Java中Integer的最大值和最小值

    从JDK1.0开始,Integer中就定义了MIN_VALUE和MAX-VALUE两个常量: /** * A constant holding the minimum value an {@code ...

  3. 从源码看java中Integer的缓存问题

    在开始详细的说明问题之前,我们先看一段代码 public static void compare1(){ Integer i1 = 127, i2 = 127, i3 = 128, i4 = 128; ...

  4. Java中Integer的源码学习

      一.开始 public final class Integer extends Number implements Comparable<Integer> 1).由于类修饰符中有关键字 ...

  5. Java中Integer类的方法

    java.lang 类 Integer java.lang.Object java.lang.Number java.lang.Integer 全部已实现的接口: Serializable, Comp ...

  6. Java中Integer和String浅谈

    Java中的基本数据类型有八种:int.char.boolean.byte.long.double.float.short.Java作为一种面向对象的编程语言,数据在Java中也是一种对象.我们用基本 ...

  7. JAVA中Integer的==和equals注意

    “equals”比较:equals(Object obj)方法,在equals(Object obj)方法中,会先判断参数中的对象obj是否是Integer类型的对象,如果是则判断值是否相同,值相同则 ...

  8. JAVA中Integer类型变量比较问题

    今天在做实验的时候,发现了一个比较奇怪的问题:两个Integer型变量用==进行比较时,有时候能成功有时候不能成功.举个例子: 代码1: Integer l1 = 122; Integer l2 = ...

  9. java中Integer与int装箱拆箱一点收获

    示例代码: class BoxIntInteger { public static void main(String[] args) { Integer a = new Integer(10111); ...

随机推荐

  1. Xcode之Alcatraz

    Alcatraz的安装和使用 转发:http://www.cnblogs.com/wendingding/p/4964661.html 一.简单说明 Alcatraz 是一款 Xcode的插件管理工具 ...

  2. Ubuntu上CUDA和CUDNN的安装

    Ubuntu上CUDA的安装 下载路径: CUDA下载 `sudo dpkg -i cuda-repo-ubuntu1504-7-5-local_7.5-18_amd64.deb` `sudo apt ...

  3. macbook pro 突破校园网inode客户端限制分享网络

    [原创] 环境: 1. macbook pro (retina) 2. mac os x 10.9 3. H3C inode for mac 7.0 分享方法: 1.打开inode联网. 2.打开设置 ...

  4. jQuery修改css属性

    jQuery CSS 操作jQuery 拥有三种用于 CSS 操作的重要函数:$(selector).css(name,value)$(selector).css({properties})$(sel ...

  5. linux分区-df

    转自:http://baike.baidu.com/link?url=tyonI3NCB3F-ytIQz72PY-8uAaUQgfFFXbyKAea1e2NiB_t5AsE0MLOLc2LcqOiS ...

  6. FZU 2110 Star

    简单暴力题,读入%lld会WA,%I64d能过. #include<cstdio> #include<cstring> #include<cmath> #inclu ...

  7. displayport-2

    上一章讲述了display-port的硬件连接,今天来说说协议层 图中可以看到,最底层是物理层,上层是连接服务层,提供的服务包括同步数据传输服务,aux链接服务,aux设备数据传输服务,在设备端也一样 ...

  8. STM32驱动TEA5767收音机模块

    Tea5767是飞利浦公司出的一款集成化的收音机芯片,大四的时候机缘巧合遇到了这个芯片,用了一下,写点资料 主要特性 TEA5767HN是一款低功耗立体声收音IC,广泛应用于手机MP3 .MP 4 播 ...

  9. Java使用POI实现数据导出excel报表

    Java使用POI实现数据导出excel报表 在上篇文章中,我们简单介绍了java读取word,excel和pdf文档内容 ,但在实际开发中,我们用到最多的是把数据库中数据导出excel报表形式.不仅 ...

  10. 从字符串拼接看JS优化原则

    来自知乎的问题:JavaScript 怎样高效拼接字符串? 请把以下用于连接字符串的JavaScript代码修改为更高效的方式: var htmlString ='< div class=”co ...