zoukankan      html  css  js  c++  java
  • java中Integer比较需要注意的问题

    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
        }
    }
  • 相关阅读:
    php 导出csv文件
    dns 服务器配置
    ettercap ARP dns 欺骗
    for循环内 执行$ajax(){}
    js 如何生成二维数组
    jquery读取csv文件并用json格式输出
    echo 换行
    cmd命令运行php,php通过cmd运行文件
    Git 常用命令整理
    图像裁剪插件
  • 原文地址:https://www.cnblogs.com/stono/p/5086400.html
Copyright © 2011-2022 走看看