Example usage for java.lang StringBuilder length

List of usage examples for java.lang StringBuilder length

Introduction

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

Prototype

int length();

Source Link

Document

Returns the length of this character sequence.

Usage

From source file:Main.java

public static UUID parseUUID(String uuidValue) {
    try {//from  ww  w. j  ava2s. c o m
        return UUID.fromString(uuidValue);
    } catch (IllegalArgumentException x) {
        StringBuilder buf = new StringBuilder(36);
        buf.append(uuidValue);

        while (buf.length() < 32) {
            buf.insert(0, '0');
        }

        buf.insert(8, '-');
        buf.insert(13, '-');
        buf.insert(18, '-');
        buf.insert(23, '-');

        return UUID.fromString(buf.toString());
    }
}

From source file:com.sunyue.util.calculator.impl.parser.AbstractExpressionParser.java

/**
 * Clear the <code>java.lang.StringBuffer</code>
 * /*  w w  w.  j ava2s.com*/
 * @param sb
 */
protected static void clear(StringBuilder sb) {
    sb.delete(0, sb.length());
}

From source file:Main.java

/**
 * join the string list with the join char sequence.
 * /*from   ww  w. j  a  v a  2 s .  c o  m*/
 * @param list
 *           the join sequence.
 * @param separator
 *           the join key word;
 * @return
 *          joined string.
 */
public static String join(List<String> list, String separator) {
    StringBuilder sb = new StringBuilder();
    for (String ele : list) {
        if (sb.length() > 0) {
            sb.append(separator);
        }
        sb.append(ele);
    }
    return sb.toString();
}

From source file:Main.java

/** Construct a string by toString()ing each item in the collection with inBetween between each item. */
public static String join(final Collection<?> items, final String inBetween) {
    final StringBuilder builder = new StringBuilder();
    for (final Object item : items) {
        if (builder.length() > 0)
            builder.append(inBetween);/*  ww  w .  j a  v a 2  s  .  co m*/
        builder.append(item);
    }

    return builder.toString();
}

From source file:Main.java

public static String join(List<String> list, String separator) {
    StringBuilder sb = new StringBuilder();
    for (String ele : list) {
        if (sb.length() > 0) {
            sb.append(separator);//  ww  w  . java 2  s. c  om
        }
        sb.append(ele);
    }
    return sb.toString();
}

From source file:Main.java

public static String implode(Iterable it, String glue) {
    StringBuilder result = new StringBuilder();
    for (Object o : it) {
        result.append(glue).append(o);/*ww w.  ja v  a  2s.  c om*/
    }
    if (result.length() > 0) {
        result.delete(0, glue.length());
    }
    return result.toString();
}

From source file:com.zimbra.cs.account.PreAuthKey.java

public static String computePreAuth(Map<String, String> params, String key) {
    TreeSet<String> names = new TreeSet<String>(params.keySet());
    StringBuilder sb = new StringBuilder();
    for (String name : names) {
        if (sb.length() > 0)
            sb.append('|');
        sb.append(params.get(name));/*from w w w  .ja  v  a2  s  . co m*/
    }
    return getHmac(sb.toString(), key.getBytes());
}

From source file:Main.java

public static String toString(Collection<?> c, char separator) {
    if (c == null) {
        return null;
    }/*  w  ww . j a v a  2  s. com*/
    StringBuilder sb = new StringBuilder();
    for (Object o : c) {
        if (o != null) {
            if (sb.length() > 0) {
                sb.append(separator);
            }
            sb.append(o.toString());
        }
    }
    return sb.toString();
}

From source file:Main.java

public static String _byteArrayToHex(byte[] a) {
    StringBuilder sb = new StringBuilder();
    for (byte b : a)
        sb.append(String.format("%02x-", b & 0xff));
    sb.deleteCharAt(sb.length() - 1);
    return sb.toString();
}

From source file:Main.java

public static String joinArray(int[] arr, String seperator) {
    StringBuilder sb = new StringBuilder();
    for (Integer i : arr) {
        sb.append(i).append(seperator);/*from  w w  w  .j  a v  a2s .co m*/
    }

    if (sb.length() > 0) {
        return sb.subSequence(0, sb.length() - seperator.length()).toString();
    }
    return sb.toString();
}