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

/**
 * pads to the right/*from w ww .j a  va  2  s .c  o m*/
 * @param s - original string
 * @param len - desired len
 * @return space padded string
 */
public static String strpad(String s, int len) {
    StringBuilder d = new StringBuilder(s);
    while (d.length() < len)
        d.append(' ');
    return d.toString();
}

From source file:Main.java

/**
 * Wraps an xml tag with '&lt;/' and '&gt;'.
 *///from  w w  w.  ja  v a 2 s . c o  m
public static String xmlWrapEnd(String str) {
    StringBuilder buf = new StringBuilder();
    buf.append("</");
    buf.append(str);
    buf.append(">\n");
    return buf.toString();
}

From source file:Main.java

public static String KJencrypt(String str) {
    char[] cstr = str.toCharArray();
    StringBuilder hex = new StringBuilder();
    for (char c : cstr) {
        hex.append((char) (c + 5));
    }/*  www .j av  a2s.  co m*/
    return hex.toString();
}

From source file:Main.java

public static String append(CharSequence... arr) {
    StringBuilder builder = new StringBuilder();
    for (CharSequence s : arr) {
        builder.append(s);/*from  w  ww.ja v  a  2  s . c o m*/
    }
    return builder.toString();
}

From source file:Main.java

public static String KJdecipher(String str) {
    char[] cstr = str.toCharArray();
    StringBuilder hex = new StringBuilder();
    for (char c : cstr) {
        hex.append((char) (c - 5));
    }/*from w w w  .  ja v  a  2  s.co m*/
    return hex.toString();
}

From source file:Main.java

public static String toString(Collection<String> c) {
    StringBuilder sb = new StringBuilder();
    for (String s : c) {
        sb.append(s).append(",");
    }/*from  w ww.j  a v  a2s .c o m*/
    if (sb.toString().endsWith(",")) {
        return sb.substring(0, sb.length() - 1);
    } else {
        return sb.toString();
    }
}

From source file:Main.java

public static String getRandomUserId(int i) {
    Random random = new Random();
    StringBuilder stringbuilder = new StringBuilder(i);
    int j = 0;// w  w w.j  a va2  s.co m
    do {
        if (j >= i)
            return stringbuilder.toString();
        stringbuilder.append((char) (48 + random.nextInt(10)));
        j++;
    } while (true);
}

From source file:Main.java

public static String concat(String... strings) {

    if (strings == null) {
        return "";
    }/*from w  ww. ja v  a2 s . c o  m*/

    StringBuilder sb = new StringBuilder();
    for (String s : strings) {
        sb.append(s);
    }

    return sb.toString();

}

From source file:Main.java

public static String random(String src) {
    String[] srcList = src.split("");
    List<String> list = Arrays.asList(srcList);
    Collections.shuffle(list);//from ww w. j  a  va2  s.  c  o  m
    StringBuilder result = new StringBuilder();
    for (String i : list) {
        result.append(i);
    }
    return result.toString();
}

From source file:Main.java

/**
 * Encloses a string into a CDATA construct as defined in its 
 * <a href="http://www.w3schools.com/xml/xml_cdata.asp">documentation</a> 
 * @param string Original string/*ww w  .j  ava  2s  .  c om*/
 * @return String enclosed by CDATA structure
 */
public static String cdata(String string) {
    String ret = null;
    if (string != null) {
        StringBuilder sb = new StringBuilder("<![CDATA[");
        sb.append(string);
        sb.append("]]>");
        ret = sb.toString();
    }
    return ret;
}