java equals

来源:互联网 发布:手机淘宝可以秒杀吗 编辑:程序博客网 时间:2024/06/02 03:26

String str="hello";//第一種if(str.equals("hello")){System.out.println("相同");}//第二種if(“hello”.equals(str)){System.out.println("相同");}

用第二種,可以防止空指針異常。



0 0
原创粉丝点击