Example usage for java.lang CharSequence length

List of usage examples for java.lang CharSequence length

Introduction

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

Prototype

int length();

Source Link

Document

Returns the length of this character sequence.

Usage

From source file:Main.java

private static String getAppropriateEncoding(CharSequence contents) {
    for (int i = 0; i < contents.length(); i++) {
        if (contents.charAt(i) > 0xFF) {
            return "UTF-8";
        }//from w w  w  .  ja v a2s .com
    }
    return null;
}

From source file:Main.java

public static int length(CharSequence string) {
    return string == null ? 0 : string.length();
}

From source file:Main.java

/**
 * Returns true if the string is null or 0-length.
 *
 * @param str the string to be examined//  w w  w. ja va 2s.  co m
 * @return true if str is null or zero length
 * @since 1.0.0
 */
public static boolean isEmpty(CharSequence str) {
    if (str == null || str.length() == 0) {
        return true;
    } else {
        return false;
    }
}

From source file:Main.java

/**
 * adjust string:/*from   w  w  w  .  j ava2  s .co  m*/
 * if string is null,or string's length is 0,return true,
 * @param strMsg
 * @return
 */
public static boolean stringIsEmpty(CharSequence strMsg) {
    if (strMsg == null || strMsg.length() == 0)
        return true;
    return false;
}

From source file:Main.java

/**
 * Helper method to validate the password
 *///from  w w  w .  j  a  v  a 2  s  .c  o m
public static boolean isPasswordValid(CharSequence password) {
    return password.length() >= 6;
}

From source file:Main.java

public static boolean isEmpty(final CharSequence cs) {
    return cs == null || cs.length() == 0;
}

From source file:Main.java

/**
 * Does one string contain another, starting at a specific offset?
 * @param text/*from   w  w  w  .  j  a v a2s.  c om*/
 * @param offset
 * @param other
 * @return
 */
public static int matchesAt(CharSequence text, int offset, CharSequence other) {
    int len = other.length();
    int i = 0;
    int j = offset;
    for (; i < len; ++i, ++j) {
        char pc = other.charAt(i);
        char tc = text.charAt(j);
        if (pc != tc)
            return -1;
    }
    return i;
}

From source file:Main.java

public static CharSequence getTrimmedString(CharSequence src) {
    if (src == null || src.length() == 0) {
        return src;
    }/*w  ww.j  a  v  a 2 s .  c  o m*/
    while (src.length() > 0 && (src.charAt(0) == '\n' || src.charAt(0) == ' ')) {
        src = src.subSequence(1, src.length());
    }
    while (src.length() > 0 && (src.charAt(src.length() - 1) == '\n' || src.charAt(src.length() - 1) == ' ')) {
        src = src.subSequence(0, src.length() - 1);
    }
    return src;
}

From source file:Main.java

public static boolean isEmpty(CharSequence str) {
    return (str == null || str.length() == 0);
}

From source file:Main.java

public static String toNumberWithDefault(CharSequence c, String def) {
    return (c == null || c.length() == 0) ? def : c + "";
}