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 byte[] hexStringToByteArray(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));
    }// w ww  .  j  a  v  a2 s . c  om
    return data;
}

From source file:Main.java

public static boolean isNotEmpty(String s) {
    return s != null && s.length() != 0 && !s.trim().equals("") && !s.trim().equals("null");
}

From source file:Main.java

public static boolean isNullOrEmpty(String s) {
    return s == null || s.length() == 0;
}

From source file:Main.java

public static boolean nullOrEmpty(String s) {
    return s == null || s.length() == 0;
}

From source file:Main.java

public static String spliteTitle(String origTitle) {
    if (origTitle.length() >= 10) {
        return origTitle.substring(0, 10) + "...";
    } else {/* w  ww .j  a va2  s. c o  m*/
        return origTitle;
    }
}

From source file:Main.java

public static byte[] hexToBytes(String s) {
    if (s.length() % 2 == 1)
        return new byte[0];

    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));
    }/*from w w w  .  j  a va  2  s  . c  om*/
    return data;
}

From source file:Main.java

public static boolean isPhoneNum(String phoneNum) {
    if (phoneNum.length() != 11)
        return false;
    if (!phoneNum.substring(0, 1).equals("1"))
        return false;
    return true;/*w w w .j  a v  a 2 s .  c o m*/
}

From source file:Main.java

public static boolean isEmpty(String s) {
    return s == null || s.length() == 0 || s.trim().equals("") || s.trim().equals("null");
}

From source file:Main.java

private static byte[] hexStringToByteArray(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));
    }/*from w  w  w  .jav a  2 s.  co m*/
    return data;
}

From source file:Main.java

public static String formatString(String str) {
    int i = str.length();
    while (i > 3) {
        str = str.substring(0, i - 3) + "," + str.substring(i - 3);
        i -= 3;/*from ww w .j a v  a 2  s . c om*/
    }
    return str;
}