List of usage examples for java.lang CharSequence length
int length();
From source file:org.apache.commons.lang3.StringUtils.java
/** * <p>Checks if the CharSequence contains only Unicode letters and * space (' ').</p>//from w w w. j a va 2 s. co m * * <p>{@code null} will return {@code false} * An empty CharSequence (length()=0) will return {@code true}.</p> * * <pre> * StringUtils.isAlphaSpace(null) = false * StringUtils.isAlphaSpace("") = true * StringUtils.isAlphaSpace(" ") = true * StringUtils.isAlphaSpace("abc") = true * StringUtils.isAlphaSpace("ab c") = true * StringUtils.isAlphaSpace("ab2c") = false * StringUtils.isAlphaSpace("ab-c") = false * </pre> * * @param cs the CharSequence to check, may be null * @return {@code true} if only contains letters and space, * and is non-null * @since 3.0 Changed signature from isAlphaSpace(String) to isAlphaSpace(CharSequence) */ public static boolean isAlphaSpace(CharSequence cs) { if (cs == null) { return false; } int sz = cs.length(); for (int i = 0; i < sz; i++) { if (Character.isLetter(cs.charAt(i)) == false && cs.charAt(i) != ' ') { return false; } } return true; }
From source file:org.apache.commons.lang3.StringUtils.java
/** * <p>Checks if the CharSequence contains only Unicode letters, digits * or space ({@code ' '}).</p>/* ww w .ja v a2 s . c om*/ * * <p>{@code null} will return {@code false}. * An empty CharSequence (length()=0) will return {@code true}.</p> * * <pre> * StringUtils.isAlphanumericSpace(null) = false * StringUtils.isAlphanumericSpace("") = true * StringUtils.isAlphanumericSpace(" ") = true * StringUtils.isAlphanumericSpace("abc") = true * StringUtils.isAlphanumericSpace("ab c") = true * StringUtils.isAlphanumericSpace("ab2c") = true * StringUtils.isAlphanumericSpace("ab-c") = false * </pre> * * @param cs the CharSequence to check, may be null * @return {@code true} if only contains letters, digits or space, * and is non-null * @since 3.0 Changed signature from isAlphanumericSpace(String) to isAlphanumericSpace(CharSequence) */ public static boolean isAlphanumericSpace(CharSequence cs) { if (cs == null) { return false; } int sz = cs.length(); for (int i = 0; i < sz; i++) { if (Character.isLetterOrDigit(cs.charAt(i)) == false && cs.charAt(i) != ' ') { return false; } } return true; }
From source file:org.apache.commons.lang3.StringUtils.java
/** * <p>Checks if the CharSequence contains only ASCII printable characters.</p> * * <p>{@code null} will return {@code false}. * An empty CharSequence (length()=0) will return {@code true}.</p> * * <pre>//from w w w . jav a2s. com * StringUtils.isAsciiPrintable(null) = false * StringUtils.isAsciiPrintable("") = true * StringUtils.isAsciiPrintable(" ") = true * StringUtils.isAsciiPrintable("Ceki") = true * StringUtils.isAsciiPrintable("ab2c") = true * StringUtils.isAsciiPrintable("!ab-c~") = true * StringUtils.isAsciiPrintable("\u0020") = true * StringUtils.isAsciiPrintable("\u0021") = true * StringUtils.isAsciiPrintable("\u007e") = true * StringUtils.isAsciiPrintable("\u007f") = false * StringUtils.isAsciiPrintable("Ceki G\u00fclc\u00fc") = false * </pre> * * @param cs the CharSequence to check, may be null * @return {@code true} if every character is in the range * 32 thru 126 * @since 2.1 * @since 3.0 Changed signature from isAsciiPrintable(String) to isAsciiPrintable(CharSequence) */ public static boolean isAsciiPrintable(CharSequence cs) { if (cs == null) { return false; } int sz = cs.length(); for (int i = 0; i < sz; i++) { if (CharUtils.isAsciiPrintable(cs.charAt(i)) == false) { return false; } } return true; }
From source file:org.apache.commons.lang3.StringUtils.java
/** * <p>Checks if the CharSequence contains only Unicode digits or space * ({@code ' '}).//from w ww.j av a 2 s . c om * A decimal point is not a Unicode digit and returns false.</p> * * <p>{@code null} will return {@code false}. * An empty CharSequence (length()=0) will return {@code true}.</p> * * <pre> * StringUtils.isNumericSpace(null) = false * StringUtils.isNumericSpace("") = true * StringUtils.isNumericSpace(" ") = true * StringUtils.isNumericSpace("123") = true * StringUtils.isNumericSpace("12 3") = true * StringUtils.isNumericSpace("ab2c") = false * StringUtils.isNumericSpace("12-3") = false * StringUtils.isNumericSpace("12.3") = false * </pre> * * @param cs the CharSequence to check, may be null * @return {@code true} if only contains digits or space, * and is non-null * @since 3.0 Changed signature from isNumericSpace(String) to isNumericSpace(CharSequence) */ public static boolean isNumericSpace(CharSequence cs) { if (cs == null) { return false; } int sz = cs.length(); for (int i = 0; i < sz; i++) { if (Character.isDigit(cs.charAt(i)) == false && cs.charAt(i) != ' ') { return false; } } return true; }
From source file:org.apache.commons.lang3.StringUtils.java
/** * <p>Checks if the CharSequence contains only whitespace.</p> * * <p>{@code null} will return {@code false}. * An empty CharSequence (length()=0) will return {@code true}.</p> * * <pre>//from w w w . j a v a2 s . c o m * StringUtils.isWhitespace(null) = false * StringUtils.isWhitespace("") = true * StringUtils.isWhitespace(" ") = true * StringUtils.isWhitespace("abc") = false * StringUtils.isWhitespace("ab2c") = false * StringUtils.isWhitespace("ab-c") = false * </pre> * * @param cs the CharSequence to check, may be null * @return {@code true} if only contains whitespace, and is non-null * @since 2.0 * @since 3.0 Changed signature from isWhitespace(String) to isWhitespace(CharSequence) */ public static boolean isWhitespace(CharSequence cs) { if (cs == null) { return false; } int sz = cs.length(); for (int i = 0; i < sz; i++) { if (Character.isWhitespace(cs.charAt(i)) == false) { return false; } } return true; }
From source file:org.apache.commons.lang3.StringUtils.java
/** * Check whether the given CharSequence contains any whitespace characters. * @param seq the CharSequence to check (may be {@code null}) * @return {@code true} if the CharSequence is not empty and * contains at least 1 whitespace character * @see java.lang.Character#isWhitespace * @since 3.0/*from w w w. ja va 2s . c o m*/ */ // From org.springframework.util.StringUtils, under Apache License 2.0 public static boolean containsWhitespace(CharSequence seq) { if (isEmpty(seq)) { return false; } int strLen = seq.length(); for (int i = 0; i < strLen; i++) { if (Character.isWhitespace(seq.charAt(i))) { return true; } } return false; }
From source file:org.apache.commons.lang3.StringUtils.java
/** * <p>Checks if the CharSequence contains only lowercase characters.</p> * * <p>{@code null} will return {@code false}. * An empty CharSequence (length()=0) will return {@code false}.</p> * * <pre>//www.ja v a 2 s .co m * StringUtils.isAllLowerCase(null) = false * StringUtils.isAllLowerCase("") = false * StringUtils.isAllLowerCase(" ") = false * StringUtils.isAllLowerCase("abc") = true * StringUtils.isAllLowerCase("abC") = false * </pre> * * @param cs the CharSequence to check, may be null * @return {@code true} if only contains lowercase characters, and is non-null * @since 2.5 * @since 3.0 Changed signature from isAllLowerCase(String) to isAllLowerCase(CharSequence) */ public static boolean isAllLowerCase(CharSequence cs) { if (cs == null || isEmpty(cs)) { return false; } int sz = cs.length(); for (int i = 0; i < sz; i++) { if (Character.isLowerCase(cs.charAt(i)) == false) { return false; } } return true; }
From source file:org.apache.commons.lang3.StringUtils.java
/** * <p>Checks if the CharSequence contains only uppercase characters.</p> * * <p>{@code null} will return {@code false}. * An empty String (length()=0) will return {@code false}.</p> * * <pre>//from w ww . j a va2 s . c om * StringUtils.isAllUpperCase(null) = false * StringUtils.isAllUpperCase("") = false * StringUtils.isAllUpperCase(" ") = false * StringUtils.isAllUpperCase("ABC") = true * StringUtils.isAllUpperCase("aBC") = false * </pre> * * @param cs the CharSequence to check, may be null * @return {@code true} if only contains uppercase characters, and is non-null * @since 2.5 * @since 3.0 Changed signature from isAllUpperCase(String) to isAllUpperCase(CharSequence) */ public static boolean isAllUpperCase(CharSequence cs) { if (cs == null || isEmpty(cs)) { return false; } int sz = cs.length(); for (int i = 0; i < sz; i++) { if (Character.isUpperCase(cs.charAt(i)) == false) { return false; } } return true; }
From source file:org.apache.commons.lang3.StringUtils.java
/** * <p>Checks if CharSequence contains a search CharSequence irrespective of case, * handling {@code null}. Case-insensitivity is defined as by * {@link String#equalsIgnoreCase(String)}. * * <p>A {@code null} CharSequence will return {@code false}.</p> * * <pre>//w w w . j a v a2 s. c o m * StringUtils.contains(null, *) = false * StringUtils.contains(*, null) = false * StringUtils.contains("", "") = true * StringUtils.contains("abc", "") = true * StringUtils.contains("abc", "a") = true * StringUtils.contains("abc", "z") = false * StringUtils.contains("abc", "A") = true * StringUtils.contains("abc", "Z") = false * </pre> * * @param str the CharSequence to check, may be null * @param searchStr the CharSequence to find, may be null * @return true if the CharSequence contains the search CharSequence irrespective of * case or false if not or {@code null} string input * @since 3.0 Changed signature from containsIgnoreCase(String, String) to containsIgnoreCase(CharSequence, CharSequence) */ public static boolean containsIgnoreCase(CharSequence str, CharSequence searchStr) { if (str == null || searchStr == null) { return false; } int len = searchStr.length(); int max = str.length() - len; for (int i = 0; i <= max; i++) { if (CharSequenceUtils.regionMatches(str, true, i, searchStr, 0, len)) { return true; } } return false; }
From source file:org.apache.commons.lang3.StringUtils.java
/** * <p>Check if a CharSequence starts with a specified prefix (optionally case insensitive).</p> * * @see java.lang.String#startsWith(String) * @param str the CharSequence to check, may be null * @param prefix the prefix to find, may be null * @param ignoreCase indicates whether the compare should ignore case * (case insensitive) or not.//from ww w. j av a2 s .com * @return {@code true} if the CharSequence starts with the prefix or * both {@code null} */ private static boolean startsWith(CharSequence str, CharSequence prefix, boolean ignoreCase) { if (str == null || prefix == null) { return str == null && prefix == null; } if (prefix.length() > str.length()) { return false; } return CharSequenceUtils.regionMatches(str, ignoreCase, 0, prefix, 0, prefix.length()); }