Example usage for java.lang String length

List of usage examples for java.lang String length

Introduction

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

Prototype

public int length() 

Source Link

Document

Returns the length of this string.

Usage

From source file:Main.java

public static String subTitle(String str) {

    if (str.length() > 4) {
        return str.substring(0, 4);
    } else {//from w  w w  .  j a  v  a2 s  . c  o m
        return str;

    }

}

From source file:Main.java

public static void drawButtonText(Canvas canvas, Paint paint, Rect btnRect, String text) {
    int nLen = text.length();
    canvas.drawText(text, btnRect.left + btnRect.width() / 2 - 4 * nLen,
            btnRect.top + btnRect.height() / 2 + nLen, paint);
}

From source file:Main.java

public static boolean isShareStrLentht(String text, int lenght) {
    return text.length() <= 120;
}

From source file:Main.java

public static boolean isEmpty(String s) {
    if (null != s && s.length() > 0)
        return false;
    return true;/*from  ww w  .  j av  a 2 s.co m*/
}

From source file:Main.java

public static boolean isLenghtStrLentht(String text, int lenght) {
    return text.length() <= lenght;
}

From source file:Main.java

public static boolean getNullCheck(String s) {
    if (s == null || s.length() == 0 || s.equals("null")) {
        return false;
    }//  w  ww  . j a  v a 2s.c om
    return true;
}

From source file:Main.java

public static boolean isMobileNumber(String mobile) {
    if (mobile.length() != 11)
        return false;
    // "^((\\d{7,8})|(0\\d{2,3}-\\d{7,8})|(1[34578]\\d{9}))$"
    Pattern p = Pattern.compile("^((1[3|5|8][0-9])|(14[5|7])|(17[0|1|6|7|8]))\\d{8}$");
    Matcher m = p.matcher(mobile);
    return m.matches();
}

From source file:Main.java

private static String timeStrFormat(String timeStr) {
    switch (timeStr.length()) {
    case 1:/*from   w ww  .j  av  a  2  s. c o  m*/
        timeStr = "0" + timeStr;
        break;
    }
    return timeStr;
}

From source file:Main.java

/**
 * Converts a hex string to a byte array.
 *//* w w w.ja  v  a  2  s  .c  o m*/
public static byte[] convertToByteArray(String s) {
    int len = s.length();
    byte[] data = new byte[len / 2];
    for (int i = 0; i < len; i += 2) {
        data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));
    }
    return data;
}

From source file:Main.java

public static byte[] hexStringToByteArray(String s) {
    if ((s.length() % 2) != 0) {
        throw new IllegalArgumentException("Bad input string: " + s);
    }/*from  w  w  w.j  a  va 2s . co  m*/

    int len = s.length();
    byte[] data = new byte[len / 2];
    for (int i = 0; i < len; i += 2) {
        data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));
    }
    return data;
}