您的位置:首页 > 其它

String a=1与String a=new String("1")的区别,以及其他包装类类似对比

2012-09-24 19:54 471 查看
public class Cmp

{

   public static void main(String[] args)

   {

         String a="abc";
String b="abc";

System.out.println(a==b);        
//true  

String a1=new String("abc");
String b1=new String("abc");

System.out.println(a1==b1);   //false
 
 
Integer c=123;
Integer d=123;
System.out.println(c==d);
          //true  ,在-128~127之间是true

Integer c1=new Integer(123);
Integer d1=new Integer(123);
System.out.println(c1==d1);     //false
Integer c2=234;
Integer d2=234;

System.out.println(c2==d2);     //false,在-128~127的范围之外是false
 
Double e=1.0;
Double f=1.0;
System.out.println(e==f);          //false
double e1=1.0;
double f1=1.0;
System.out.println(e1==f1);     //true
 
Float g=1.0f;
Float h=1.0f;
System.out.println(g==h);           //false
float g1=1.0f;
float h1=1.0f;
System.out.println(g1==h1);       //true

   }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  string integer class c
相关文章推荐