作了个小测试equals 和==

public class Sample{ long length; public Sample(long l){length = l;} public static void main(String arg[]){ Sample s1,s2,s3; s1=new Sample(21L); s2=new Sample(21L); s3=s2; String st1="hello"; String st2="hello"; String st3= new String("hello"); int i=3; Integer j=new Integer(3); float f =3.000f; Float fl =new Float(3.0f); Float f2 =new Float(3.0f); long m=21L; System.out.println(fl.equals(i));//false System.out.println(j.equals(f));//false System.out.println(s1.equals(s2));//true??false!!!!! System.out.println(fl.equals(f2));//true System.out.println(s2==s3);//true System.out.println(s1==s3);//false System.out.println(st1==st2);//true System.out.println(st3==st2);//false System.out.println(fl.equals(3));//false System.out.println(fl==f);//true if(i==f) System.out.println("equal1");//do if(i==fl) System.out.println("equal2");//do if(f2==fl) System.out.println("equal3");//undo if(i==f2) System.out.println("equal4");//do //if(s1==fl)System.out.println("equal3");cannot be compiled! } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值