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:it.attocchi.utils.StringFunc.java

public static String concat(String separator, String... strings) {
    StringBuilder sb = new StringBuilder();

    for (String aString : strings) {
        if (StringUtils.isNotBlank(aString)) {
            if (sb.length() > 0)
                sb.append(separator);//from  w  ww  .j  av a  2  s.  c  o m
            sb.append(aString);
        }
    }

    return sb.toString();
}

From source file:Main.java

public static String join(List list, String separator) {
    StringBuilder sb = new StringBuilder();
    String ele;//from   ww w.  j a v  a  2s.co  m
    for (Iterator i$ = list.iterator(); i$.hasNext(); sb.append(ele)) {
        ele = (String) i$.next();
        if (sb.length() > 0)
            sb.append(separator);
    }

    return sb.toString();
}

From source file:com.stealthyone.mcb.stbukkitlib.utils.StringUtils.java

/**
 * Converts a list of strings into a single string, separated by commas.
 *
 * @param list List to convert to a string.
 * @return Newly created string.//ww  w.  j  a  v a2 s.co m
 */
public static String stringListToString(List<String> list) {
    if (list == null)
        return "";
    StringBuilder sb = new StringBuilder();
    for (String item : list) {
        if (sb.length() > 0) {
            sb.append(", ");
        }
        sb.append(item);
    }
    return sb.toString();
}

From source file:Main.java

/**
 *
 * @param separator character to put between arguments
 * @param args items to string together//  ww w  . j  ava 2s  . c  om
 * @param <T> type of items
 * @return "" for empty list, otherwise arg1 + separator + arg2 + separator + ...
 */
@Nonnull
public static <T> String join(String separator, Iterable<T> args) {
    StringBuilder builder = new StringBuilder();

    for (T project : args) {
        builder.append(project);
        builder.append(separator);
    }

    if (builder.length() > separator.length()) {
        return builder.substring(0, builder.length() - separator.length());
    } else {
        return "";
    }
}

From source file:Main.java

/**
 * merge the refer variable by target mainRefer and otherRefer, refer variable is something like: 'user,handler''
 * @param mainRefer the main refer variable
 * @param otherRefer the other refer variable
 * @return the new he refer variable//from  w  ww  . j  a va 2  s. c o m
 */
public static String mergeReferVariable(String mainRefer, String otherRefer) {
    if (mainRefer == null)
        return otherRefer;
    if (otherRefer == null)
        return mainRefer;
    if (mainRefer.equals(otherRefer))
        return mainRefer;

    final String[] mainStrs = mainRefer.split(",");
    final String[] otherStrs = otherRefer.split(",");

    for (int i = 0, size = mainStrs.length; i < size; i++) {
        sSet.add(mainStrs[i]);
    }
    for (int i = 0, size = otherStrs.length; i < size; i++) {
        sSet.add(otherStrs[i]);
    }
    StringBuilder sb = new StringBuilder();
    for (String str : sSet) {
        sb.append(str).append(",");
    }
    //delete last
    sb.deleteCharAt(sb.length() - 1);
    sSet.clear();
    return sb.toString();
}

From source file:com.google.flightmap.parsing.util.StringUtils.java

/**
 * Returns mixed-case version of {@code text}.
 * <p>/* w ww.  j a  va2 s.  co  m*/
 * The first letter of each word is capitalized, the rest are lower case.
 * Words are delimited by spaces and special characters (except single-quote).
 * "REID-HILLVIEW" becomes "Reid-Hillview".
 * 
 * @return mixed-case version of {@code text} with each word capitalized.
 */
public static String capitalize(final String text) {
    final StringBuilder sb = new StringBuilder(WordUtils.capitalize(text.toLowerCase()));
    boolean makeNextLetterUpper = false;
    for (int i = 0; i < sb.length(); ++i) {
        final char cur = sb.charAt(i);
        if (Character.isWhitespace(cur)) {
            continue; // Skip whitespace
        } else if (Character.isLetterOrDigit(cur)) {
            if (makeNextLetterUpper) {
                sb.setCharAt(i, Character.toUpperCase(cur));
                makeNextLetterUpper = false;
            } else {
                continue; // Skip character if no change is neded
            }
        } else { // Not whitespace, letter or digit:  we assume punctuation.
            makeNextLetterUpper = cur != '\''; // Ignore single quote (John'S, Susie'S, ...)
        }
    }
    return sb.toString();
}

From source file:Main.java

/**
 * buildStringFromArray/* w  ww .j ava 2 s .c  o m*/
 *
 * @param stringArray the String[] to convert
 * @param separator   the string separator
 * @return the separated string
 */
public static String buildStringFromArray(ArrayList<String> stringArray, String separator) {
    if (stringArray.size() > 0) {
        StringBuilder nameBuilder = new StringBuilder();
        for (String n : stringArray) {
            nameBuilder.append(n).append(separator);
        }
        nameBuilder.deleteCharAt(nameBuilder.length() - 1);
        return nameBuilder.toString();
    } else {
        return null;
    }
}

From source file:Main.java

public static String i(int[] iArr) {
    StringBuilder stringBuilder = new StringBuilder(32);
    stringBuilder.append('(');
    for (int append : iArr) {
        stringBuilder.append(append).append(',');
    }/*  ww  w. j  a  va  2s .com*/
    stringBuilder.setCharAt(stringBuilder.length() - 1, ')');
    return stringBuilder.toString();
}

From source file:edu.ucla.cs.scai.linkedspending.index.Utils.java

public static String normalizeAndFilterStopWords(String s) {
    StringBuilder sb = new StringBuilder();
    for (String w : normalizeWords(s).split(" ")) {
        if (!stopwords.contains(w)) {
            if (sb.length() > 0) {
                sb.append(" ");
            }/*  w w w  . jav  a  2  s . com*/
            sb.append(w);
        }
    }
    return sb.toString();
}

From source file:Main.java

public static String readLineLimit(Reader reader, int limit) throws IOException {
    StringBuilder sb = new StringBuilder();

    for (int i = 0; i < limit; i++) {
        int c = reader.read(); //Read in single character
        if (c == -1) {
            return ((sb.length() > 0) ? sb.toString() : null);
        }/*from  ww w.ja v a2 s  .  c  o m*/

        if (((char) c == '\n') || ((char) c == '\r')) { //Found end of line, break loop.
            break;
        }

        sb.append((char) c); // String is not over and end line not found
    }

    return sb.toString(); //end of line was found.
}