- 五、 字符串比较:
- 9、
- Compares two Strings, returning true if they are equal.
- nulls are handled without exceptions. Two null
- references are considered to be equal. The comparison is case sensitive.
- 判断两个字符串是否相等,有非空处理。 StringUtils.equals(null, null) = true StringUtils.equals(null, "abc") = false StringUtils.equals("abc", null) = false StringUtils.equals("abc", "abc") = true StringUtils.equals("abc", "ABC") = false
- @param str1 the first String, may be null
- @param str2 the second String, may be null
- @return true if the Strings are equal, case sensitive, or
- both null
- @see java.lang.String#equals(Object)
- public static boolean equals(String str1, String str2)
- 10、
- Compares two Strings, returning true if they are equal ignoring
- the case.
- nulls are handled without exceptions. Two null
- references are considered equal. Comparison is case insensitive.
- 判断两个字符串是否相等,有非空处理。忽略大小写 StringUtils.equalsIgnoreCase(null, null) = true StringUtils.equalsIgnoreCase(null, "abc") = false StringUtils.equalsIgnoreCase("abc", null) = false StringUtils.equalsIgnoreCase("abc", "abc") = true StringUtils.equalsIgnoreCase("abc", "ABC") = true
- @param str1 the first String, may be null
- @param str2 the second String, may be null
- @return true if the Strings are equal, case insensitive, or
- both null
- @see java.lang.String#equalsIgnoreCase(String)
- public static boolean equalsIgnoreCase(String str1, String str2)
- 六、 IndexOf 处理
- 11、
- Finds the first index within a String, handling null.
- This method uses {@link String#indexOf(String)}.
- A null String will return -1.
- 返回要查找的字符串所在位置,有非空处理 StringUtils.indexOf(null, *) = -1 StringUtils.indexOf(*, null) = -1 StringUtils.indexOf("", "") = 0 StringUtils.indexOf("aabaabaa", "a") = 0 StringUtils.indexOf("aabaabaa", "b") = 2 StringUtils.indexOf("aabaabaa", "ab") = 1 StringUtils.indexOf("aabaabaa", "") = 0
- @param str the String to check, may be null
- @param searchStr the String to find, may be null
- @return the first index of the search String,
- -1 if no match or null string input
- @since 2.0
- public static int indexOf(String str, String searchStr)
- 12、
- Finds the first index within a String, handling null.
- This method uses {@link String#indexOf(String, int)}.
- A null String will return -1.
- A negative start position is treated as zero.
- An empty ("") search String always matches.
- A start position greater than the string length only matches
- an empty search String.
- 返回要由指定位置开始查找的字符串所在位置,有非空处理 StringUtils.indexOf(null, *, *) = -1 StringUtils.indexOf(*, null, *) = -1 StringUtils.indexOf("", "", 0) = 0 StringUtils.indexOf("aabaabaa", "a", 0) = 0 StringUtils.indexOf("aabaabaa", "b", 0) = 2 StringUtils.indexOf("aabaabaa", "ab", 0) = 1 StringUtils.indexOf("aabaabaa", "b", 3) = 5 StringUtils.indexOf("aabaabaa", "b", 9) = -1 StringUtils.indexOf("aabaabaa", "b", -1) = 2 StringUtils.indexOf("aabaabaa", "", 2) = 2 StringUtils.indexOf("abc", "", 9) = 3
- @param str the String to check, may be null
- @param searchStr the String to find, may be null
- @param startPos the start position, negative treated as zero
- @return the first index of the search String,
- -1 if no match or null string input
- @since 2.0
- public static int indexOf(String str, String searchStr, int startPos)
复制代码 |