Example usage for java.lang CharSequence charAt

List of usage examples for java.lang CharSequence charAt

Introduction

In this page you can find the example usage for java.lang CharSequence charAt.

Prototype

char charAt(int index);

Source Link

Document

Returns the char value at the specified index.

Usage

From source file:ths.commons.util.StringUtils.java

/**
 * <p>Checks if a CharSequence is whitespace, empty ("") or null.</p>
 *
 * <pre>//w w  w . j a  v a 2  s  .  c o  m
 * StringUtils.isBlank(null)      = true
 * StringUtils.isBlank("")        = true
 * StringUtils.isBlank(" ")       = true
 * StringUtils.isBlank("bob")     = false
 * StringUtils.isBlank("  bob  ") = false
 * </pre>
 *
 * @param cs  the CharSequence to check, may be null
 * @return {@code true} if the CharSequence is null, empty or whitespace
 */
public static boolean isBlank(CharSequence cs) {
    int strLen;
    if (cs == null || (strLen = cs.length()) == 0) {
        return true;
    }
    for (int i = 0; i < strLen; i++) {
        if ((Character.isWhitespace(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 ' '})./* ww w.j a va  2s  . com*/
 * 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 Unicode letters and
 * space (' ').</p>//from   w  w  w. j  a  va  2  s . c  o 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 whitespace.</p>
 *
 * <p>{@code null} will return {@code false}.
 * An empty CharSequence (length()=0) will return {@code true}.</p>
 *
 * <pre>/* w  w  w  .  ja va2s. c  om*/
 * 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

/**
 * <p>Checks if the CharSequence contains only Unicode letters, digits
 * or space ({@code ' '}).</p>// ww w . j  ava 2  s  .c  o m
 *
 * <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 ww.  ja  va2  s.c  o m
 * 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

/**
 * 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/*  ww  w. java 2 s  . 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>/*  ww  w  .j  a va2  s .  com*/
 * 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   www.j a va2s  .co m
 * 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 the CharSequence contains only Unicode digits.
 * 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 false}.</p>
 *
 * <pre>//  ww w. j  a  va 2s.  c  o  m
 * StringUtils.isNumeric(null)   = false
 * StringUtils.isNumeric("")     = false
 * StringUtils.isNumeric("  ")   = false
 * StringUtils.isNumeric("123")  = true
 * StringUtils.isNumeric("12 3") = false
 * StringUtils.isNumeric("ab2c") = false
 * StringUtils.isNumeric("12-3") = false
 * StringUtils.isNumeric("12.3") = false
 * </pre>
 *
 * @param cs  the CharSequence to check, may be null
 * @return {@code true} if only contains digits, and is non-null
 * @since 3.0 Changed signature from isNumeric(String) to isNumeric(CharSequence)
 * @since 3.0 Changed "" to return false and not true
 */
public static boolean isNumeric(CharSequence cs) {
    if (cs == null || cs.length() == 0) {
        return false;
    }
    int sz = cs.length();
    for (int i = 0; i < sz; i++) {
        if (Character.isDigit(cs.charAt(i)) == false) {
            return false;
        }
    }
    return true;
}