/1. 比较两个字符串是否相等,如果两个均为null,则也认为相等/
StringUtils.equals("", ""); //结果是true
StringUtils.equals(null, null); //结果是true
StringUtils.equals(null, ""); //结果是false
StringUtils.equals("",null); //结果是false
StringUtils.equals(null,""); //结果是false
StringUtils.equalsIgnoreCase("ss", "Ss"); //不区分大小写--结果是true
原文链接:https://blog.csdn.net/aiqinhai1016_/article/details/9929447
这种情况下二者是一样的,
String a = "";
String b = "";
System.out.println(StringUtils.equals(a,b));//true
System.out.println(a.equals(b));//true
这种情况下是会出问题的,
String a = null;
String b = null;
System.out.println(StringUtils.equals(a,b));//true
System.out.println(a.equals(b));//报空指针,因为a为null
其实我主要是想表达第2种,也是实际工作中会碰到的, 所以,这里还推荐使用StringUtils.equals(),
不管2个那个为null,都可以防止空指针,如果要用a.equals(b)这个,那前提是a不能为null,b可以为null,这样也可以防止空指针,工作中可能你不知道那个会为null,所以还是用StringUtils.equals()这个比较好.
原文链接:https://blog.csdn.net/z786352260/article/details/105264298
3万+

被折叠的 条评论
为什么被折叠?



