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
}
}
java中Integer比较需要注意的问题的更多相关文章
- java中Integer 和String 之间的转换
java中Integer 和String 之间的转换 将数组转换成字符串:char[] array = {'a','b','c','d','e'};String str = new String(ar ...
- Java中Integer的最大值和最小值
从JDK1.0开始,Integer中就定义了MIN_VALUE和MAX-VALUE两个常量: /** * A constant holding the minimum value an {@code ...
- 从源码看java中Integer的缓存问题
在开始详细的说明问题之前,我们先看一段代码 public static void compare1(){ Integer i1 = 127, i2 = 127, i3 = 128, i4 = 128; ...
- Java中Integer的源码学习
一.开始 public final class Integer extends Number implements Comparable<Integer> 1).由于类修饰符中有关键字 ...
- Java中Integer类的方法
java.lang 类 Integer java.lang.Object java.lang.Number java.lang.Integer 全部已实现的接口: Serializable, Comp ...
- Java中Integer和String浅谈
Java中的基本数据类型有八种:int.char.boolean.byte.long.double.float.short.Java作为一种面向对象的编程语言,数据在Java中也是一种对象.我们用基本 ...
- JAVA中Integer的==和equals注意
“equals”比较:equals(Object obj)方法,在equals(Object obj)方法中,会先判断参数中的对象obj是否是Integer类型的对象,如果是则判断值是否相同,值相同则 ...
- JAVA中Integer类型变量比较问题
今天在做实验的时候,发现了一个比较奇怪的问题:两个Integer型变量用==进行比较时,有时候能成功有时候不能成功.举个例子: 代码1: Integer l1 = 122; Integer l2 = ...
- java中Integer与int装箱拆箱一点收获
示例代码: class BoxIntInteger { public static void main(String[] args) { Integer a = new Integer(10111); ...
随机推荐
- webView.loadUrl("file:///android_asset/table3.html")出现中文乱码的问题
webSettings.setDefaultTextEncodingName("UTF-8");
- PAT (Advanced Level) 1016. Phone Bills (25)
简单模拟题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm& ...
- PAT (Advanced Level) 1013. Battle Over Cities (25)
并查集判断连通性. #include<iostream> #include<cstring> #include<cmath> #include<algorit ...
- [Big Data]从Hadoop到Spark的架构实践
摘要:本文则主要介绍TalkingData在大数据平台建设过程中,逐渐引入Spark,并且以Hadoop YARN和Spark为基础来构建移动大数据平台的过程. 当下,Spark已经在国内得到了广泛的 ...
- Struts2---OGNL表达式和EL表达式
在action里放入actioncontext的变量值 ActionContext.getContext().put("forumList", forumList); 在jsp里如 ...
- C# 开发系列(一)
1.开发环境搭建: win7 32位系统,然后安装 visual studio 2012. 2.将 .net_framework 加入到windows 的环境变量当中. C:\Windows\Micr ...
- css控制div显示/隐藏方法及2种方法比较原码 - czf164的专栏 - 博客频道 - CSDN.NET
body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...
- Nutz 第一个Demo
Nut 是什么 我这就不多解释 知道是个javaweb框架 如想仔细了解请移步管网 http://nutzam.com/ 一.项目结构(直接看图 ) 需要注意的是 src和conf 都为源码包 con ...
- 基础数据结构之(Binary Trees)
从头开始刷ACM,真的发现过去的很多漏洞,特别越是基础的数据结构,越应该学习得精,无论是ACM竞赛,研究生考试,还是工程上,对这些基础数据结构的应用都非常多,深刻理解非常必要.不得不说最近感触还是比较 ...
- pyhton字符编码问题--decode和encode方法
1 decode和encode方法 字符串在Python内部的表示是unicode编码,因此,在做编码转换时,通常需要以unicode作为中间编码,即先将其他编码的字符串解码(decode)成uni ...