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 <A> String join(Iterable<A> combination, String sep) {
    StringBuilder sb = new StringBuilder();
    for (A s : combination) {
        if (sb.length() > 0) {
            sb.append(sep);/*  w w w.  j a v a  2  s  . com*/
        }
        sb.append(s);
    }
    return sb.toString();
}

From source file:Main.java

public static String getFieldString(String fields) {
    String[] fieldArr = fields.split("[,]");
    StringBuilder result = new StringBuilder();

    for (int i = 0, len = fieldArr.length; i < len; i++) {
        if (i > 0) {
            result.append("&");
        }//from   ww w .  ja  v  a 2s.c o  m
        result.append("fields=").append(fieldArr[i]);
    }

    return result.toString();
}

From source file:Main.java

public static String removeDigit(String numStr, boolean which) {
    StringBuilder builder = new StringBuilder();
    for (char c : numStr.toCharArray()) {
        if (isOddDigit(c) ^ which) {
            builder.append(c);//from w ww. j  a  v  a 2s.c om
        }
    }
    return builder.toString();
}

From source file:Main.java

public static String getDeviceInfoText(BluetoothDevice device, int rssi, byte[] scanRecord) {
    return new StringBuilder().append("Name: ").append(device.getName()).toString();
}

From source file:Main.java

public static String removeDesiredDigit(String numStr, char digit) {
    StringBuilder builder = new StringBuilder();
    for (char c : numStr.toCharArray()) {
        if (c != digit) {
            builder.append(c);//  www .  j  a va2s. c o  m
        }
    }
    return builder.toString();
}

From source file:Main.java

public static <T> String parseArrayToString(T[] imgsIds) {
    StringBuilder stringBuilder = new StringBuilder();
    for (T t : imgsIds) {
        stringBuilder.append(t).append(",");
    }/*  w  w  w .j a va2 s  .  com*/
    int index = stringBuilder.lastIndexOf(",");
    if (index == (stringBuilder.toString().length() - 1)) {
        stringBuilder.deleteCharAt(index);
    }
    return stringBuilder.toString();
}

From source file:Main.java

public static String arrayToString(String message, ArrayList<Integer> arr) {
    StringBuilder resString = new StringBuilder();
    resString.append(message);//  w  ww.j av a 2s.  c o  m
    for (int i : arr) {
        resString.append(i + 1).append(", ");
    }
    resString.delete(resString.length() - 2, resString.length());
    return resString.toString();
}

From source file:Main.java

public static String print(int... array) {
    StringBuilder sb = new StringBuilder();
    sb.append("[");
    if (array != null && array.length > 0)
        for (int i = 0; i < array.length; i++)
            sb.append(array[i]).append(i == array.length - 1 ? "]" : ", ");
    else {//w  w  w  .  j  a v  a 2s.  co  m
        if (array != null && array.length == 0)
            sb.append("empty");

        sb.append("]");
    }
    return sb.toString();
}

From source file:Main.java

final public static String encodeLongToHex(final int color) {
    StringBuilder builder = new StringBuilder();
    String colorStr = Long.toHexString(color);
    int i = 8 - colorStr.length();
    while (i != 0) {
        builder.append("0");
        i--;/*  ww w  . j  av  a2s .co m*/
    }
    builder.append(Long.toHexString(color));
    return builder.toString();
}