Example usage for java.lang StringBuilder toString

List of usage examples for java.lang StringBuilder toString

Introduction

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

Prototype

@Override
    @HotSpotIntrinsicCandidate
    public String toString() 

Source Link

Usage

From source file:Main.java

public static String repeat(String s, int n) {
    if (s.length() == 1) {
        byte[] bb = new byte[n];
        Arrays.fill(bb, s.getBytes()[0]);
        return new String(bb);
    } else {/*from w w  w .  j a v  a 2  s  . co m*/
        StringBuilder ret = new StringBuilder();
        for (int i = 0; i < n; i++)
            ret.append(s);
        return ret.toString();
    }
}

From source file:Main.java

private static String buildWhitespace(int numChars) {
    StringBuilder sb = new StringBuilder();

    for (int i = 0; i < numChars; i++) {
        sb.append(" ");
    }/*from   w  ww  .ja v  a  2 s  .  c o m*/

    return sb.toString();
}

From source file:Main.java

public static String generateConnectKey(String host, int port) {
    StringBuilder sb = new StringBuilder();
    sb.append(host);//from  ww w  .j a v  a2  s .  c o m
    sb.append(":");
    sb.append(String.valueOf(port));
    return sb.toString();
}

From source file:Main.java

public static String getHexArray(byte[] arr) {
    StringBuilder sb = new StringBuilder();
    for (byte c : arr) {
        sb.append(String.format("%02X ", c));
    }//w  w  w . j a  v  a 2  s . co m
    return sb.toString();
}

From source file:Main.java

/**
 * Converts a list of Strings to a single String
 * //from  www  .ja v  a2s .c  om
 * @param strings
 * @return
 */
private static String outputStrings(List<?> strings) {
    StringBuilder builder = new StringBuilder();
    for (Object string : strings)
        builder.append(string);

    return builder.toString();
}

From source file:Main.java

/**
 * Concatenates Strings together using a StringBuilder. This is faster than using the +-operator.
 * @param args the Objects to append//from  ww  w.  j a v  a  2  s.  co  m
 * @return a concatenation of the Objects in {@code args}
 */
public static String buildString(Object... args) {
    StringBuilder b = new StringBuilder();
    for (Object obj : args) {
        b.append(obj);
    }
    return b.toString();
}

From source file:Main.java

public static String byteArrayToHex(byte[] a) {
    StringBuilder sb = new StringBuilder(a.length * 2);
    for (byte b : a)
        sb.append(String.format("%02x", b & 0xff));
    return sb.toString();
}

From source file:Main.java

public static String bytes2Hex(byte[] bytes) {
    StringBuilder sb = new StringBuilder();
    for (byte b : bytes) {
        sb.append(String.format("%02X ", b));
    }/*from  w  ww.  ja  v  a  2 s .c o  m*/
    return sb.toString();
}

From source file:Main.java

public static String ipv6toStr(byte[] src) {
    assert src.length == 16;
    StringBuilder sb = new StringBuilder(39);
    ipv6toStr(sb, src, 0, 8);/*  w  ww  . j  a  v a 2 s.c o m*/
    return sb.toString();
}

From source file:Main.java

public static String repeat(String s, int cnt) {
    StringBuilder sb = new StringBuilder(s.length() * cnt);
    for (int i = 0; i < cnt; i++) {
        sb.append(s);//from   w ww .j  a v  a 2 s.c o m
    }
    return sb.toString();
}