Operations on {@link java.lang.String} that are
* null
safe.
Checks that the String does not contain certain characters.
* *A null
String will return true
.
* A null
invalid character array will return true
.
* An empty String ("") always returns true.
* StringUtils.containsNone(null, *) = true * StringUtils.containsNone(*, null) = true * StringUtils.containsNone("", *) = true * StringUtils.containsNone("ab", "") = true * StringUtils.containsNone("abab", "xyz") = true * StringUtils.containsNone("ab1", "xyz") = true * StringUtils.containsNone("abz", "xyz") = false ** * @param str the String to check, may be null * @param invalidChars a String of invalid chars, may be null * @return true if it contains none of the invalid chars, or is null * @since 2.0 */ public static boolean containsNone(String str, String invalidChars) { if (str == null || invalidChars == null) { return true; } return containsNone(str, invalidChars.toCharArray()); } // ContainsNone //----------------------------------------------------------------------- /** *
Checks that the String does not contain certain characters.
* *A null
String will return true
.
* A null
invalid character array will return true
.
* An empty String ("") always returns true.
* StringUtils.containsNone(null, *) = true * StringUtils.containsNone(*, null) = true * StringUtils.containsNone("", *) = true * StringUtils.containsNone("ab", '') = true * StringUtils.containsNone("abab", 'xyz') = true * StringUtils.containsNone("ab1", 'xyz') = true * StringUtils.containsNone("abz", 'xyz') = false ** * @param str the String to check, may be null * @param invalidChars an array of invalid chars, may be null * @return true if it contains none of the invalid chars, or is null * @since 2.0 */ public static boolean containsNone(String str, char[] invalidChars) { if (str == null || invalidChars == null) { return true; } int strSize = str.length(); int validSize = invalidChars.length; for (int i = 0; i < strSize; i++) { char ch = str.charAt(i); for (int j = 0; j < validSize; j++) { if (invalidChars[j] == ch) { return false; } } } return true; } // ---------------------------------------------------------------------- /** *
Checks if an array of Objects is empty or null
.
true
if the array is empty or null
* @since 2.1
*/
public static boolean isEmpty(char[] array) {
if (array == null || array.length == 0) {
return true;
}
return false;
}
// Empty checks
//-----------------------------------------------------------------------
/**
* Checks if a String is empty ("") or null.
* ** StringUtils.isEmpty(null) = true * StringUtils.isEmpty("") = true * StringUtils.isEmpty(" ") = false * StringUtils.isEmpty("bob") = false * StringUtils.isEmpty(" bob ") = false ** *
NOTE: This method changed in Lang version 2.0. * It no longer trims the String. * That functionality is available in isBlank().
* * @param str the String to check, may be null * @returntrue
if the String is empty or null
*/
public static boolean isEmpty(String str) {
return str == null || str.length() == 0;
}
}