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

private static String readStream(InputStream in) throws IOException {
    StringBuilder sb = new StringBuilder();
    BufferedReader r = new BufferedReader(new InputStreamReader(in), 1024);
    for (String line = r.readLine(); line != null; line = r.readLine()) {
        sb.append(line);/*from  w  w  w.  j  av a2 s.  c  om*/
    }
    in.close();
    return sb.toString();
}

From source file:Main.java

public static String bytesToHexString(byte[] paramArrayOfByte) {
    StringBuilder localStringBuilder = new StringBuilder();
    if ((paramArrayOfByte == null) || (paramArrayOfByte.length <= 0)) {
        return null;
    }// ww  w . j  a  v  a2  s.c  o  m
    char[] arrayOfChar = new char[2];
    for (int i = 0;; i++) {
        if (i >= paramArrayOfByte.length) {
            return localStringBuilder.toString().toUpperCase();
        }
        arrayOfChar[0] = Character.forDigit(0xF & paramArrayOfByte[i] >>> 4, 16);
        arrayOfChar[1] = Character.forDigit(0xF & paramArrayOfByte[i], 16);
        localStringBuilder.append(arrayOfChar);
    }
}

From source file:Main.java

public static String append(CharSequence... arr) {
    StringBuilder builder = new StringBuilder();
    for (CharSequence s : arr) {
        builder.append(s);/*from  w  w w .  j  a  va2  s  .  c  om*/
    }
    return builder.toString();
}

From source file:Main.java

private static String join(List<String> list, String delim) {
    StringBuilder buf = new StringBuilder();
    int num = list.size();
    for (int i = 0; i < num; i++) {
        if (i != 0)
            buf.append(delim);/*from w ww . j ava  2 s .  c  om*/
        buf.append((String) list.get(i));
    }
    return buf.toString();
}

From source file:Main.java

private static String toHexEncode(byte[] bytes) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < bytes.length; i++) {
        int low = bytes[i] & 0xF;
        int high = (bytes[i] >>> 4) & 0xF;
        sb.append(Character.forDigit(high, 16));
        sb.append(Character.forDigit(low, 16));
    }//from  ww w  . j av a2  s . co m
    return sb.toString();
}

From source file:Main.java

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

From source file:Main.java

public static String toStringUntil(byte[] b, int pos, byte until) {
    StringBuilder str = new StringBuilder();

    while (true) {
        if (b.length <= pos) {
            return null;
        }// w  w w .  j  a  v a  2 s. c o m

        byte ch = b[pos];

        if (ch == until) {
            break;
        }
        str.append((char) ch);
        pos++;
    }

    String ret = str.toString();
    return ret;
}

From source file:Main.java

public static String a(byte[] arg5) {
    StringBuilder v1 = new StringBuilder();
    int v0;//from  w w w. j a  v a 2 s  .co  m
    for (v0 = 0; v0 < arg5.length; ++v0) {
        String v2 = Integer.toHexString(arg5[v0] & 255);
        if (v2.length() == 1) {
            v1.append("0").append(v2);
        } else {
            v1.append(v2);
        }
    }

    return v1.toString();
}

From source file:Main.java

public static String convertStackTraceToString(StackTraceElement[] stackTraceElements) {
    StringBuilder message = new StringBuilder();
    int min = Math.min(stackTraceElements.length, 4);
    for (int i = 2; i < min; i++) {
        StackTraceElement element = stackTraceElements[i];
        message.append(element.getClassName()).append(": ").append(element.getMethodName()).append("\n");
    }//from   ww w.j  a va2  s.  c  om
    return message.toString();
}

From source file:Main.java

public static String map2String(Map<String, String> map) {
    StringBuilder result = new StringBuilder();

    if (map == null || map.size() == 0)
        return "";

    for (String key : map.keySet()) {
        result.append(key).append("=").append(map.get(key)).append("&");
    }/*from  www.ja v  a2 s.c om*/
    return result.substring(0, result.length() - 1);
}