Integer a=new Integer(3);
Integer b=new Integer(3);
System.out.println(a==3);
System.out.println(b==3);
System.out.println(a==b);

解决方案 »

  1.   

    true
    true
    true
    when -128 <= i <=127 --> i == new Integer(i) ? true : false;//always true
      

  2.   

    因为Integer是int的包装类 JDK自从1.5(5.0)版本以后,就引入了自动拆装箱的语法,也就是在进行基本数据类型和对应的包装类转换时,系统将自动进行  
    所以判断a==3时候   a被自动转换为int型 
    而a==b的时候比较的是两个对象   两个不同的对象的地址肯定不同  
      

  3.   

    System.out.println(a==b); // false
    I was wrong...
      

  4.   

    有错
    System.out.println(a==3);
    System.out.println(b==3);
      

  5.   

    有错
    System.out.println(a==3);
    System.out.println(b==3);
      

  6.   

    我刚测试一下,不错没问题,三个都是TRUE,TRUE,TRUE
      

  7.   

    我觉得应该是
    true  
    true 
    false他们的产生应该和
    内存中的堆栈有关系
    理论上因该是这样的。。
    但不知道为何程序运行却都是
    true
    true
    true 
      

  8.   

    Java中关于Integer有几处需要注意:1.自动装箱拆箱 2.缓存

    Integer a=new Integer(3);
    Integer b=new Integer(3);
    Integer  c=4,d=4;//自动装箱,等效于c=Integer.valueOf(4),d=Integer.valueOf(4);System.out.println(a==3);//自动拆箱
    System.out.println(b==3);
    System.out.println(a==b);//==与+是Java中唯一被重载的两个运算符,两个对象进行比较时会比较内存地址
    System.out.println(c==d);//因为-128~127之间的整数被缓存,所以他们指向同一个地址
    结果:
    true
    true
    false
    true
      

  9.   

    true
    true
    false
    LS分析的很详细
      

  10.   

    true true false,  
      

  11.   

    执行结果应该是
    a==3 比较的是值,因此结果为true
    b==3 同理,因此结果也为true
    而a,b是实例化的两个对象,a==b,比较的首地址、值和类型,因此结果为false
      

  12.   

    对自动装箱拆箱、缓存是啥意思不是很了解,按我理解为
    System.out.println(a==3);
    System.out.println(b==3);
    肯定没问题。
    System.out.println(a==b);
    a,b都是对象,所指的地址不同,所以为false
      

  13.   

    true;
    true;
    false;
    a==3,b==3肯定是对的,而a==b就不对了,a和b是两个不同的对象,在内存中的地址是不同的,所以a是不等于b的!
      

  14.   

    9l正解:package com.jsu.test;public class Test { /**
     * @param args
     */
    public static void main(String[] args) { Integer x=new Integer(1);
    Integer y=new Integer(1);
    Integer a = 3;
    Integer b = 3;
    Integer c = 10, d = 10;
    System.out.println("x==y?:"+(x==y));
    System.out.println(a == 3);
    System.out.println(b == 3);
    System.out.println("a==b?:"+(a==b));
    System.out.println("c==d?:"+(c==d)); }}
      

  15.   

    a == 3 比较的是值
    a == b 比较的是对象。对象地址不同
      

  16.   

    true,true,false
    a==3呢会跟值比较,因为3是常量,放在常量池里
    a==b呢这是对象之间的比较
      

  17.   

    true,true,true.自动装箱时对值从-128-127之的,它们被装箱为对象后,会在内存中被重用。
      

  18.   

           
    Integer a=new Integer(3);
    Integer b=new Integer(3);
    Integer  c=4,d=4;//自动装箱,等效于c=Integer.valueOf(4),d=Integer.valueOf(4);System.out.println(a==3);//自动拆箱
    System.out.println(b==3);
    System.out.println(a==b);//==与+是Java中唯一被重载的两个运算符,两个对象进行比较时会比较内存地址
    System.out.println(c==d);//因为-128~127之间的整数被缓存,所以他们指向同一个地址
    true
    true
    false
    true
    高人啊。。
      

  19.   

    Integer a=new Integer(3);
    integer b=3;
    这两者有什么不同呢
      

  20.   

    Integer i=100;   
    Integer j=100;  
    System.out.println(i ==j );  //(1) true 
    System.out.println(i.intValue()==j.intValue());  //(1-1) true  
      
    Integer i1=200;   
    Integer j1=200; 
    System.out.println(i ==j);  //(2) false
    System.out.println(i.intValue() ==j.intValue() );  //(2) true

            Integer a=200;   
            Integer b=200;   
            int c=200; 
            int d=200;
            System.out.println("a==c  "+(a==c));   //a==c  true
            System.out.println("b==c  "+(b==c));   //b==c  true
            System.out.println("a==b  "+(a==b));   //a==b  false
            System.out.println("c==d  "+(c==d));   //c==d  true
            
            Integer a1=new Integer(3);
            Integer b1=new Integer(3);
            Integer  c1=4,d1=4;//自动装箱,等效于c=Integer.valueOf(4),d=Integer.valueOf(4);        System.out.println(a1==3);//自动拆箱
            System.out.println(b1==3);
            System.out.println(a1==b1);//==与+是Java中唯一被重载的两个运算符,两个对象进行比较时会比较内存地址
            System.out.println(c1==d1);//因为-128~127之间的整数被缓存,所以他们指向同一个地址true
    true
    true
    true
    a==c  true
    b==c  true
    a==b  false
    c==d  true
    true
    true
    false
    true
      

  21.   

            Integer  c2=400,d2=400;
            System.out.println(c2==d2); //false
      

  22.   


    上边的人给的答案都是windows下的jdk编译结果。如果在Linux上,这段代码编译都无法通过。拿一个对象与一个内置类型比较是不可接受的。不信的人可以试试既然java跨平台,那么写的代码就要注意跨平台。
      

  23.   

    来csdn四年了!这个问题可说月月见
      

  24.   

    true
    true
    flase
    前俩个比较的是值,第三个比较的是IP地址,第三个事对象的比较,应该用if(a.equals("b"))对对象进行比较,刚才有一楼说他测试过时true把我下一跳...我也跟着测试了一下,
    结果是:
    true
    true
    flase