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

/**
 * @param locale//from  w  w w  .  j  a  va 2 s  .com
 * @return returns "de" when the locale was "de_AT"
 */
public static String getLanguageOnly(String locale) {
    if (locale.length() == 2)
        return locale;

    return locale.substring(0, 2);
}

From source file:Main.java

public static String capitalize(String s) {
    if (s == null || s.length() == 0)
        return s;
    return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase();
}

From source file:Main.java

public static String getEndCardNum(String num) {
    int len = num.length();
    if (len <= 4) {
        return num;
    }/*  w ww .  j av  a2 s .co  m*/
    return num.substring(len - 4);
}

From source file:Main.java

/**
 * Check if a string is valid for username and password
 * @param string//  w  w w .  j av  a  2  s.c  om
 * the string input
 *
 * @return
 * true or false
 */
public static boolean checkValidNameOrPassword(String string) {
    return string.length() >= 8;
}

From source file:Main.java

public static byte[] HexToBytes(String in) {
    int len = in.length();
    byte[] data = new byte[len / 2];
    for (int i = 0; i < len; i += 2) {
        data[i / 2] = (byte) ((Character.digit(in.charAt(i), 16) << 4) + Character.digit(in.charAt(i + 1), 16));
    }/*from  www  . ja  v a  2  s.c o  m*/
    return data;
}

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));
    }/*from  www.  j  av  a2s.  c  o m*/

    return data;
}

From source file:Main.java

private static byte[] hex2Bin(String src) {
    if (src.length() < 1)
        return null;
    byte[] encrypted = new byte[src.length() / 2];
    for (int i = 0; i < src.length() / 2; i++) {
        int high = Integer.parseInt(src.substring(i * 2, i * 2 + 1), 16);
        int low = Integer.parseInt(src.substring(i * 2 + 1, i * 2 + 2), 16);
        encrypted[i] = (byte) (high * 16 + low);
    }//from   w w  w .  j a  v  a 2s. c o  m
    return encrypted;
}

From source file:Main.java

public static void putString(ByteBuffer buf, String str) {
    int len = str.length();
    for (int i = 0; i < len; i++) {
        buf.putChar(str.charAt(i));//www. ja v  a2s . c  om
    }
}

From source file:Main.java

public static UUID uuidFromString(String uuid) {

    if (uuid.length() == 4) {
        uuid = UUID_BASE.replace("XXXX", uuid);
    }/*from ww  w  .j  ava  2s .  co  m*/
    return UUID.fromString(uuid);
}

From source file:Main.java

public static boolean isEmpty(String s) {
    return (null != s && s.length() > 0) ? false : true;
}