Example usage for java.lang StringBuilder StringBuilder

List of usage examples for java.lang StringBuilder StringBuilder

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public StringBuilder() 

Source Link

Document

Constructs a string builder with no characters in it and an initial capacity of 16 characters.

Usage

From source file:Main.java

public static String arrayToString(String[] arr) {
    if (arr == null)
        return "<Null>";
    StringBuilder b = new StringBuilder();
    for (String str : arr) {
        b.append(str);/*from  ww w . ja va  2 s.c  o m*/
        b.append(" ");
    }
    return b.toString();
}

From source file:Main.java

public static String abbreviate(String text) {
    String[] words = text.split("\\s");

    StringBuilder builder = new StringBuilder();
    int i = 0;/*from  www . j a  va 2 s .co  m*/
    while (i < words.length && builder.length() < 2) {
        String word = words[i].trim();
        if (word.length() > 0)
            builder.append(Character.toUpperCase(word.charAt(0)));
        i++;
    }

    return builder.toString();
}

From source file:Main.java

public static String join(Collection col, String delimiter) {
    StringBuilder builder = new StringBuilder();
    boolean firstItem = true;
    for (Object item : col) {
        if (!firstItem)
            builder.append(delimiter);/*  w  ww . j av a  2 s . c o  m*/
        else
            firstItem = false;

        builder.append(item);
    }
    return builder.toString();
}

From source file:Main.java

public static String mergeHits(ArrayList<String> processedHits) {
    StringBuilder htmlBuilder = new StringBuilder();
    for (String elem : processedHits) {
        htmlBuilder.append(elem);//from ww  w.j  a v  a2s. co  m
        htmlBuilder.append("<hr/>");
    }

    return htmlBuilder.toString();
}

From source file:Main.java

public static String parseByte2HexStr(byte buf[]) {
    StringBuilder stringBuilder = new StringBuilder();
    for (byte b : buf) {
        String hex = Integer.toHexString(b & 0xFF);
        if (hex.length() == 1) {
            hex = '0' + hex;
        }//from   www .java2s . c  o m
        stringBuilder.append(hex.toUpperCase());
    }
    return stringBuilder.toString();
}

From source file:Main.java

private static String unescape(String str) {
    StringBuilder sb = new StringBuilder();
    String[] codeStrs = str.split("\\\\u");
    for (String codeStr : codeStrs) {
        if (codeStr.isEmpty()) {
            continue;
        }/*from  w  w  w .  j av  a 2s .c o  m*/
        try {
            if (codeStr.length() <= 4) {
                sb.append(Character.valueOf((char) Integer.parseInt(codeStr, 16)));
            } else {
                sb.append(Character.valueOf((char) Integer.parseInt(codeStr.substring(0, 4), 16)));
                sb.append(codeStr.substring(4));
            }
        } catch (NumberFormatException e) {
            sb.append(codeStr);
        }
    }
    return sb.toString();
}

From source file:Main.java

public static String intTimeToString(int secs) {
    StringBuilder sb = new StringBuilder();
    int[] hourMinSec = new int[3];
    hourMinSec[0] = secs / 3600;//www. j  a  va  2  s. c om
    hourMinSec[1] = (secs - hourMinSec[0] * 3600) / 60;
    hourMinSec[2] = secs - hourMinSec[0] * 3600 - hourMinSec[1] * 60;
    for (int i = 0; i < hourMinSec.length; i++) {
        if (i == hourMinSec.length - 1 && hourMinSec[i] == 0)
            continue;
        if (i > 0)
            sb.append(":");
        sb.append(hourMinSec[i] >= 10 ? hourMinSec[i] : ("0" + hourMinSec[i]));

    }
    return sb.toString();
}

From source file:Main.java

public static String getCommaSeparatedStringFromArray(ArrayList list) {
    StringBuilder result = new StringBuilder();

    for (int i = 0; i < list.size(); i++) {
        result.append(list.get(i));//www .  ja v a 2s .  c om
        result.append(",");
    }

    return result.length() > 0 ? result.substring(0, result.length() - 1) : "";
}

From source file:Main.java

public static String getUnTypedTemplateName(String methodName) {
    StringBuilder sb = new StringBuilder();

    sb.append("method_");
    sb.append(methodName);//  ww  w .  ja v  a 2s. c o m

    return sb.toString();
}

From source file:Main.java

public static String list2String(List<String> list, String spaceCharacter) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < list.size(); i++) {
        sb.append(list.get(i));/*from  w w w .  j av  a  2 s  .co m*/
        if (i != list.size() - 1) {
            sb.append(spaceCharacter);
        }
    }
    return sb.toString();
}