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 arrayListToCsv(ArrayList<String> values) {
    StringBuilder csv = new StringBuilder();

    for (int i = 0; i < values.size(); i++) {
        csv.append(values.get(i));//from   w  w  w .j ava2  s . c  om
        if (i < values.size() - 1) {
            csv.append(",");
        }
    }

    return csv.toString();
}

From source file:Main.java

/** Join into string */
public static String join(String[] x) {
    StringBuilder sb = new StringBuilder();
    for (String token : x) {
        sb.append(token).append(" ");
    }/* w  w w . ja va 2  s .  c  o m*/
    return sb.toString().trim();
}

From source file:Main.java

public static String toUserEnteredString(List<String> term) {
    final StringBuilder builder = new StringBuilder();
    for (String part : term) {
        if (builder.length() != 0) {
            builder.append(' ');
        }/*from  ww w  . ja  v  a  2  s . c  o  m*/
        builder.append(part);
    }
    return builder.toString();
}

From source file:Main.java

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

From source file:Main.java

public static String toStringCollection(Collection list, String sep) {
    StringBuilder sb = new StringBuilder();
    for (Object s : list) {
        sb.append(s.toString());//from   w  w w  . jav  a2  s . c  om
        sb.append(sep);
    }
    return sb.toString();
}

From source file:Main.java

private static String intJoin(int[] aArr, String sSep) {
    StringBuilder sbStr = new StringBuilder();
    for (int i : aArr) {
        sbStr.append(i);//ww w.j a  va  2  s  .c  om
        sbStr.append(sSep);
    }
    return sbStr.toString();
}

From source file:Main.java

public static String getDistanceString(List<String> list) {
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("&origin=").append(list.get(0));
    stringBuilder.append("&destination=").append(list.get(list.size() - 1));
    stringBuilder.append("&waypoints=");
    for (int i = 1; i < list.size() - 1; i++) {
        stringBuilder.append(list.get(i));
        if (i != list.size() - 2)
            stringBuilder.append("|");
    }//from   ww w. java 2s .c o  m
    return stringBuilder.toString();
}

From source file:Main.java

public static String getRandomMacAddress() {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < 6; i++) {
        builder.append(getRandomMixString(2));
        builder.append(i == 5 ? "" : ":");
    }//from  www . j  ava2 s .  c om
    return builder.toString();
}

From source file:Main.java

public static String getTagName(final String tag) {
    final StringBuilder result = new StringBuilder();
    for (int i = 0; i < tag.length(); i++) {
        final char character = tag.charAt(i);
        switch (character) {
        case '<':
            result.append("&lt;");
            break;
        case '>':
            result.append("&gt;");
            break;
        case '\"':
            result.append("&quot;");
            break;
        case '\'':
            result.append("&#039;");
            break;
        case '\\':
            result.append("&#092;");
            break;
        case '&':
            result.append("&amp;");
            break;
        case ' ':
            break;
        default:/*from w  ww . j  ava2 s  .c  o  m*/
            result.append(character);
        }
    }
    return result.toString();
}

From source file:Main.java

public static String enquoteIdentifier(String s) {
    char[] raw = s.toCharArray();
    StringBuilder stringBuilder = new StringBuilder();
    for (char c : raw) {
        if (c < ' ' || c > '') {
            stringBuilder.append("\\u").append(String.format("%04x", c));
            continue;
        }/*from  w w w . j  a  v  a 2  s.c  om*/
        stringBuilder.append(c);
    }
    return stringBuilder.toString();
}