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 toRegularHashCode(String string) {
    final String hexHashCode = Integer.toHexString(string.hashCode());
    final StringBuilder stringBuilder = new StringBuilder(hexHashCode);
    while (stringBuilder.length() < 8) {
        stringBuilder.insert(0, '0');
    }//  ww  w.j ava2s. c  om
    return stringBuilder.toString();
}

From source file:Main.java

public static String sortAndFlattenNameList(List<String> names) {
    Collections.sort(names);//from   ww  w  .j a va2s. c  o m

    StringBuilder sb = new StringBuilder();

    for (String name : names) {
        sb.append(name + ", ");
    }

    String flattenedNames = sb.toString();

    if (flattenedNames.length() > 2) {
        // drop the last comma and space
        flattenedNames = flattenedNames.substring(0, flattenedNames.length() - 2);
    }

    return flattenedNames;
}

From source file:Main.java

/**
 * Get comma separated string from collection
 * /*from   www . j ava  2s  .  c o  m*/
 * @param strings
 * @return
 */
public static String getCommaSeparatedString(Collection<String> strings) {
    if (strings != null && !strings.isEmpty()) {
        Iterator<String> it = strings.iterator();
        StringBuilder sb = new StringBuilder(it.next());
        while (it.hasNext()) {
            sb.append("," + it.next());
        }
        return sb.toString();
    } else {
        return null;
    }
}

From source file:com.aqnote.shared.cryptology.util.lang.CommonUtil.java

public static String mergeString(String... strs) {
    StringBuilder sb = new StringBuilder();
    for (String str : strs) {
        sb.append(str);//from   www  .  ja  v  a 2 s. co  m
    }
    return sb.toString();
}

From source file:com.marklogic.contentpump.utilities.XMLUtil.java

public static String convertToCDATA(String arg) {
    StringBuilder sb = new StringBuilder();
    sb.append("<![CDATA[");
    sb.append(arg);//from w  w w .j  av a  2s . c  o m
    sb.append("]]>");
    return sb.toString();
}

From source file:com.sm.store.test.LoadTestStoreClient.java

public static String createString(int size) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < size; i++)
        sb.append("String createString, client send " + i);
    return sb.toString();
}

From source file:io.apiman.common.util.Basic.java

public static String encode(String username, String password) {
    String up = username + ':' + password;
    StringBuilder builder = new StringBuilder();
    builder.append("Basic ");
    builder.append(Base64.encodeBase64String(up.getBytes()));
    return builder.toString();
}

From source file:Main.java

/**
 * Run a command and return its output./*from   www .  j  a v a2s.  co  m*/
 */
public static String systemOut(String command) throws Exception {
    int c;
    String[] cmd = new String[3];
    cmd[0] = System.getProperty("SHELL", "/bin/sh");
    cmd[1] = "-c";
    cmd[2] = command;
    Process p = Runtime.getRuntime().exec(cmd);

    BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
    StringBuilder s = new StringBuilder();
    while ((c = r.read()) != -1) {
        s.append((char) c);
    }
    p.waitFor();

    return s.toString();
}

From source file:Main.java

public static String RandomString(int length) {
    String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    Random rnd = new Random();

    StringBuilder sb = new StringBuilder(length);
    for (int i = 0; i < length; i++) {
        sb.append(AB.charAt(rnd.nextInt(AB.length())));
    }/* ww  w.  jav a  2 s . c  o m*/
    return sb.toString();

}

From source file:Main.java

private static String toReadableString(byte[] bytes) {
    StringBuilder sb = new StringBuilder(bytes.length);
    for (byte b : bytes) {
        sb.append(getReadableChar(b));/*from  w  ww.j ava 2  s. co  m*/
    }
    return sb.toString();
}