"System.out.println(a1==b1);" is false is because a1 and b1 are not the some objects though they have same value

解决方案 »

  1.   

    和c一样,new 操作也是分配一块内存。虽然java说他没有指针,但是java中的
    许多数据类型都使用名字作为指针的,比如 String,Vector,Hashtable等
    a==b是指内存位置相等
    a.equles(b)是指变量内容相等我曾经写过一段代码:
    String a;
    Vector v=new Vector();
    for(i=0;i<5;i++)
    {
       a=""+i;
       v.addElement(a);
    }
    如果你把v中的东西取出来看的话,发现都是5
    为什么?就是因为没有用a=new String(""+i);
    v中所存的地址都是一个不知我这么说你能明白吗
       
      

  2.   

    String a="123"; String b="123;
    a 和 b 都指向常量“123“的地址String a=new String("123"); b=new String("123");
      a 和 b 开辟了各自的内存空间~~
      

  3.   

    String a="123"; 
    String b="123";
    System.out.println(a==b);  
    为true,我觉得此时a和b不应该是地址,而应是地址中所指向的内容String a1=new String("123"); 
    String b1=new String("123");
    System.out.println(a1==b1);
    为false,此时的a和b才是不同的地址,指向各自新创建的空间
      

  4.   

    to 楼上
     a和b当然是地址~~