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 String getAudioDuration(int second) {

    StringBuilder sb = new StringBuilder();
    sb.append(second).append("\"");
    return sb.toString();
}

From source file:Main.java

public static String getHour(int Hour) {
    StringBuilder hourStr = new StringBuilder();
    if (Hour < 10) {
        hourStr.append("0" + Hour);
    } else {//from w  ww.j a  v  a  2s  .com
        hourStr.append(Hour);
    }

    return hourStr.toString();
}

From source file:Main.java

public static String nmtokenize(String cs) {
    StringBuilder s = new StringBuilder();
    for (int i = 0; i < cs.length(); i++) {
        char c = cs.charAt(i);
        if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c == '_')
            s.append(c);/* ww  w  .j a  va  2  s  . c  o  m*/
        else if (c != ' ')
            s.append("." + Integer.toString(c));
    }
    return s.toString();
}

From source file:Main.java

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

From source file:Main.java

public static String int2ipForm(long ipInt) {
    StringBuilder sb = new StringBuilder();
    String s1 = (ipInt & 0xFF) + "";
    String s2 = ((ipInt >> 8) & 0xFF) + "";
    String s3 = ((ipInt >> 16) & 0xFF) + "";
    String s4 = ((ipInt >> 24) & 0xFF) + "";
    sb.append(s4).append(".").append(s3).append(".").append(s2).append(".").append(s1);
    return sb.toString();
}

From source file:Main.java

public static String hexToASCII(String hex) {
    StringBuilder sb = new StringBuilder();
    // Convert Hex 0232343536AB into two characters stream.
    for (int i = 0; i < hex.length() - 1; i += 2) {
        String output = hex.substring(i, (i + 2));
        int decimal = Integer.parseInt(output, 16);
        sb.append((char) decimal);
    }//w  w w. j a v  a 2s .  c  o m
    return sb.toString();
}

From source file:Main.java

static String toDbColumName(String name) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0, size = name.length(); i < size; i++) {
        char c = name.charAt(i);
        if (c >= 'A' && c <= 'Z') {
            sb.append("_" + Character.toLowerCase(c));
        } else {// w  w  w .  ja v a 2  s.  c  om
            sb.append(c);
        }
    }
    return sb.toString();
}

From source file:Main.java

public static String getEANList(String[] eans) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < eans.length; i++) {
        if (i > 0)
            sb.append("  ");
        sb.append(Integer.toString(i + 1) + "/" + eans[i]);
    }/*w ww.  jav a 2 s  .co  m*/
    return sb.toString();
}

From source file:Main.java

public static String convertVertical(String str) {
    StringBuilder sp = new StringBuilder();
    for (int i = 0; i < str.length(); i++) {
        sp.append(str.charAt(i));//  w  w w  .  j  a  v  a 2 s .  com
        sp.append('\n');
    }
    return sp.toString();
}

From source file:Main.java

public static String IntToBitSetString(int value) {
    StringBuilder sb = new StringBuilder();
    while (value > 0) {
        sb.append(value % 2);/*from   w ww  . j  a  va  2  s  .  c o m*/
        value = value >> 1;
    }
    return sb.toString();
}