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

private static String deriveLongerString(String str) {
    StringBuilder sb = new StringBuilder(str);
    StringBuilder builder = new StringBuilder();
    builder.append(sb.toString().toLowerCase());
    builder.append(sb.toString().toUpperCase());
    StringBuilder result = new StringBuilder();
    result.append(sb);//  w w w  . ja  va 2 s.c om
    result.append(mix(builder.toString()));
    result.append(mix(builder.reverse().toString()));
    return result.toString();
}

From source file:Main.java

public static String implode(Iterator it) {
    StringBuilder sb = new StringBuilder();
    while (it.hasNext()) {
        sb.append(it.next());/*from  ww  w  . ja  v  a2s .  c  om*/
        sb.append(", ");
    }

    return sb.toString().replaceAll(", +$", "");
}

From source file:Main.java

/**
 * bit representation of a BitSet/*w  w w  .j  av  a 2  s  .  c om*/
 * suitable for dumps and debugging
 * @param b - the BitSet
 * @return string representing the bits (i.e. 011010010...)
 */
public static String bitSet2String(BitSet b) {
    int len = b.size();
    len = (len > 128) ? 128 : len;
    StringBuilder d = new StringBuilder(len);
    for (int i = 0; i < len; i++)
        d.append(b.get(i) ? '1' : '0');
    return d.toString();
}

From source file:Main.java

public static byte[] hexStringToByteArray(String s) {
    if (s.length() % 2 != 0) {
        StringBuilder stringBuilder = new StringBuilder(s);
        stringBuilder.insert(s.length() - 1, "0");
        s = stringBuilder.toString();
    }/*from  w w  w.ja v a2 s  .  c  o  m*/

    int len = s.length();
    byte[] data = new byte[len / 2];
    for (int i = 0; i < len; i += 2) {
        data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));
    }
    return data;
}

From source file:Main.java

/**
 * @param s/*  w  w  w . j  a v a2 s  .  c o  m*/
 * @return
 */
public static String getFirstLetterUppercased(String s) {
    StringBuilder sb = new StringBuilder(s.substring(0, 1).toUpperCase(Locale.getDefault()));
    sb.append(s.substring(1));
    return sb.toString();
}

From source file:Main.java

/**
 * Run a command and return its output./*from  w w  w . ja  va 2s . com*/
 */
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 reverse(String input) {
    StringBuilder output = new StringBuilder();
    for (int i = input.length() - 1; i >= 0; i--) {
        output.append(input.charAt(i));/*from w w  w  .  java  2  s.c  o  m*/
    }
    return output.toString();
}

From source file:Main.java

public static String getPid() {
    StringBuilder pid = new StringBuilder(Build.MANUFACTURER).append(" ").append(Build.MODEL).append(" - ")
            .append(Build.VERSION.RELEASE);

    return pid.toString();
}

From source file:Main.java

public static String combine(JSONArray[] s, String glue) {
    int k = s.length;
    if (k == 0)/*from   w w w.  j  a  va 2 s  .  c  om*/
        return null;
    StringBuilder out = new StringBuilder();
    out.append(s[0]);
    for (int x = 1; x < k; ++x)
        out.append(glue).append(s[x]);
    return out.toString();
}

From source file:com.snaplogic.snaps.lunex.RequestProcessor.java

private static String formatResponse(StringBuilder response) {
    if (!response.toString().endsWith(CLOSEBRACKET) && !response.toString().startsWith(OPENBRACKET)) {
        response.insert(0, OPENBRACKET).append(CLOSEBRACKET);
    }/* ww  w .  j a  va 2  s  . c om*/
    return response.toString();
}