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

public static String decode(String unicodeStr) {
    if (unicodeStr == null) {
        return null;
    }//from  ww w.  j  a va  2s . c  o m
    StringBuffer retBuf = new StringBuffer();
    int maxLoop = unicodeStr.length();
    for (int i = 0; i < maxLoop; i++) {
        if (unicodeStr.charAt(i) == '\\') {
            if ((i < maxLoop - 5) && ((unicodeStr.charAt(i + 1) == 'u') || (unicodeStr.charAt(i + 1) == 'U'))) {
                try {
                    retBuf.append((char) Integer.parseInt(unicodeStr.substring(i + 2, i + 6), 16));
                    i += 5;
                } catch (NumberFormatException localNumberFormatException) {
                    retBuf.append(unicodeStr.charAt(i));
                }
            } else {
                retBuf.append(unicodeStr.charAt(i));
            }
        } else {
            retBuf.append(unicodeStr.charAt(i));
        }
    }
    return retBuf.toString();
}

From source file:Main.java

public static String getOddOrEvenString(String src, int type) {
    if (src == null || src.length() <= 0) {
        return "";
    }/*from w  w  w.  jav  a2  s  .co  m*/
    StringBuffer sb = new StringBuffer();
    int sbLength = src.length();
    for (int i = 0; i < sbLength; i++) {
        if (i % 2 == type) {
            sb.append(src.charAt(i));
        }
    }
    return sb.toString();
}

From source file:Main.java

private static String bytesToHex(byte[] b) {
    char hexDigit[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
    StringBuffer buf = new StringBuffer();
    for (int j = 0; j < b.length; j++) {
        buf.append(hexDigit[(b[j] >> 4) & 0x0f]);
        buf.append(hexDigit[b[j] & 0x0f]);
    }//from www.ja  v  a 2 s .  c  o m
    return buf.toString();
}

From source file:Main.java

public static String ageChangeToBinaryString(int i) {
    String s = Integer.toBinaryString(i);
    Object obj = s;/*from   w ww. j a va 2s  . co m*/
    if (s.length() < 7) {
        obj = new StringBuffer();
        for (i = 0; i < 7 - s.length(); i++) {
            ((StringBuffer) (obj)).append("0");
        }

        ((StringBuffer) (obj)).append(s);
        obj = ((StringBuffer) (obj)).toString();
    }
    return ((String) (obj));
}

From source file:Utils.java

/**
 * // w w w.j  a  v a2 s. c  o m
 */
public static String getElementText(Element element) {
    StringBuffer buffer = new StringBuffer();
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) {
            buffer.append(node.getNodeValue());
        }
    }
    return buffer.toString();
}

From source file:Main.java

public static String list2String(List<Integer> list) {
    if (list == null || list.size() == 0)
        return "";
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < list.size(); i++) {
        Integer obj = list.get(i);
        sb.append(obj.toString());/*from w  w  w .  ja  va 2s.  c om*/
        if (i != list.size() - 1)
            sb.append(",");
    }
    return sb.toString();
}

From source file:Main.java

public static String arrayToString(Object[] objs, String separator) {
    if (objs == null) {
        return "[null]";
    }/*from www  . jav a 2 s .c o  m*/

    StringBuffer result = new StringBuffer();
    if (objs.length > 0) {
        result.append(objs[0] != null ? objs[0].toString() : objs[0]);
        for (int i = 1; i < objs.length; i++) {
            result.append(separator);
            result.append(objs[i] != null ? objs[i].toString() : objs[i]);
        }
    }
    return result.toString();
}

From source file:Utils.java

public static final String breakLinesHTML(String s, int width) {
    if (s == null)
        return null;

    StringBuffer buffer = new StringBuffer();
    buffer.append("<html><body><font face=\"Arial\" size=\"-1\">");
    int p = 0;/*from   w  w w. ja va 2 s. c om*/
    char c;
    for (int i = 0; i < s.length(); i++) {
        c = s.charAt(i);
        if (((p >= width) && (c == ' ')) || (c == '\n')) {
            buffer.append("<br>");
            p = 0;
        } else {
            buffer.append(c);
        }
        p++;
    }
    buffer.append("</font></body></html>");
    return buffer.toString();
}