JAVA中字符串比较equals和equalsIgnoreCase的区别
3个回答
展开全部
字符串比较,看下面的举个栗子:
System.out.println("aBc".equals("abc"));//false
System.out.println("aBc".equalsIgnoreCase("abc"));//true 忽略大小写的比较
当不知道方法的作用,点进去看源码的注释:可以用翻译工具翻译可以猜个八九不离十
/**
* Compares this {@code String} to another {@code String}, ignoring case
* considerations. Two strings are considered equal ignoring case if they
* are of the same length and corresponding characters in the two strings
* are equal ignoring case.
*
* <p> Two characters {@code c1} and {@code c2} are considered the same
* ignoring case if at least one of the following is true:
* <ul>
* <li> The two characters are the same (as compared by the
* {@code ==} operator)
* <li> Applying the method {@link
* java.lang.Character#toUpperCase(char)} to each character
* produces the same result
* <li> Applying the method {@link
* java.lang.Character#toLowerCase(char)} to each character
* produces the same result
* </ul>
*
* @param anotherString
* The {@code String} to compare this {@code String} against
*
* @return {@code true} if the argument is not {@code null} and it
* represents an equivalent {@code String} ignoring case; {@code
* false} otherwise
*
* @see #equals(Object)
*/
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
equals()方法比较字符串是区分大小写的
equalsIgnoreCase()方法比较字符串内容是不区分大小写的
比如:
String str = "abc";
System.out.println(str.equals("ABC"));//false
System.out.println(str.equalsIgnoreCase("ABC"));//true
equalsIgnoreCase()方法比较字符串内容是不区分大小写的
比如:
String str = "abc";
System.out.println(str.equals("ABC"));//false
System.out.println(str.equalsIgnoreCase("ABC"));//true
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
equalsIgnoreCase不区分大小写
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询