Example usage for java.lang StringBuffer StringBuffer

List of usage examples for java.lang StringBuffer StringBuffer

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public StringBuffer() 

Source Link

Document

Constructs a string buffer with no characters in it and an initial capacity of 16 characters.

Usage

From source file:Main.java

private static String intSetToString(List<?> list) {
    final StringBuffer dataSB = new StringBuffer();

    for (int i = 0; i < list.size(); i++) {
        dataSB.append(list.get(i));/*from  ww w . ja  v  a2 s . c o  m*/
        if (i < list.size() - 1) {
            dataSB.append(SEPERATOR);
        }
    }
    return dataSB.toString();
}

From source file:Main.java

public static String arrayToString(Object[] objArr) {
    if (objArr == null || objArr.length == 0) {
        return null;
    }/*from w  w  w  .j  a v a 2 s  . c  o  m*/

    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < objArr.length; i++) {
        buf.append((i > 0 ? "," : "") + objArr[i]);
    }
    return buf.toString();
}

From source file:Main.java

private static String longSetToString(List<?> list) {
    final StringBuffer dataSB = new StringBuffer();

    for (int i = 0; i < list.size(); i++) {
        dataSB.append(list.get(i));//from ww  w. j av  a2 s . co  m
        if (i < list.size() - 1) {
            dataSB.append(SEPERATOR);
        }
    }
    return dataSB.toString();
}

From source file:Utils.java

public static final String breakLines(String s, int width) {
    s = "    " + s;
    int n = 0;//from  www  . ja v  a2 s .co m
    boolean moreLines = true;
    StringBuffer buffer = new StringBuffer();
    if ((s == null) || (s.length() <= width))
        return s;
    while (moreLines) {
        for (int i = width; i > 0; i--) {
            if (s.charAt(n + i) == ' ') {
                buffer.append(s.substring(n, n + i) + "\n    ");
                n = n + i + 1;
                break;
            }
        }
        if ((n + width) >= s.length()) {
            buffer.append(s.substring(n));
            moreLines = false;
        }
    }
    return buffer.toString();
}

From source file:Main.java

public static String subStringWithByte(String str, int length) {
    if (str.length() == 0 || length == 0)
        return "";
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < str.length() && length > 0; i++) {
        char tmp = str.charAt(i);
        buf.append(tmp);/*from  w  w w  .j  a  va  2s  .c  o  m*/
        if (tmp > 0 && tmp < 127) {
            length -= 1;
        } else {
            length -= 2;
        }
    }

    return buf.toString();
}

From source file:Main.java

public static String getDeditPaymentXml(String cardHolder, String cardNum, String cardSec, String cardExp,
        String cardPin) {/*from   w  ww .jav  a  2s.c  om*/
    StringBuffer buffer = new StringBuffer();
    buffer.append("<payment>");
    buffer.append("<type>Dedit</type>");
    buffer.append("<cardHolder>" + cardHolder + "</cardHolder>");
    buffer.append("<cardNum>" + cardNum + "</cardNum>");
    buffer.append("<cardSec>" + cardSec + "</cardSec>");
    buffer.append("<cardExp>" + cardExp + "</cardExp>");
    buffer.append("<cardPin>" + cardPin + "</cardPin>");
    buffer.append("</payment>");

    return buffer.toString();
}

From source file:Main.java

public static String getRandom(int num) {
    StringBuffer sbf = new StringBuffer();
    for (int i = 0; i < num; i++) {
        int random = (int) (Math.random() * (RANDOMS.length()));
        sbf.append(RANDOMS.charAt(random));
    }/*ww  w.jav  a 2  s.co m*/
    return sbf.toString();

}

From source file:Main.java

public static String toTitleCase(String givenString) {
    if (givenString.length() > 0) {
        String[] arr = givenString.split(" ");
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < arr.length; i++) {
            sb.append(Character.toUpperCase(arr[i].charAt(0))).append(arr[i].substring(1)).append(" ");
        }/*from ww w .  j a v  a2 s . com*/
        return sb.toString().trim();
    }
    return "";
}

From source file:Main.java

static String tocsv(int[] arr) {
    final StringBuffer buf = new StringBuffer();
    final int count = arr.length;
    if (count > 0) {
        buf.append(arr[0]);/*from   w w  w  . j  a v  a2s.  c o m*/
    }
    for (int i = 1; i < count; ++i) {
        buf.append(",");
        buf.append(arr[i]);
    }

    return buf.toString();
}

From source file:Main.java

public static String getLevel(String xpath, int level) {
    String[] paths = split(xpath);
    StringBuffer b = new StringBuffer();
    for (int i = 0; i < level; i++) {
        b.append(paths[i]);/*ww  w.  ja  v a  2 s .c  o  m*/
        b.append(' '); // compensates the slash
    }
    b.append(paths[level]);
    b.append('/');
    return b.toString();
}