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 final String decodeInterfereWord(String src) {
    StringBuffer sb = new StringBuffer();
    for (int index = 0, size = src.length(); index < size; index++) {
        if (index % 2 == 0) {
            continue;
        }/*from   w  w w  .j  av  a2s .  c o m*/
        sb.append(src.charAt(index));
    }
    return sb.toString();
}

From source file:Main.java

public static String arrayToString(String[] array) {
    StringBuffer strBuffer = new StringBuffer();
    for (int i = 0; i < array.length; i++) {
        if (i == 0) {
            strBuffer.append(array[i]);//from  w  w w  .  jav a 2s  . co  m
        } else {
            strBuffer.append(";" + array[i]);
        }
    }
    return strBuffer.toString();
}

From source file:Main.java

public static String getCacheName(String... params) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < params.length; i++) {
        if (null != params[i]) {
            sb.append(params[i]);/*from  w  w w. java 2s.c  o m*/

        }
        if (i != params.length - 1) {
            sb.append("_");
        }
    }
    return sb.toString();
}

From source file:Main.java

public static String getVerticalText(String text) {
    StringBuffer stringBuffer = new StringBuffer();
    if (text != null && text.length() > 0) {
        int length = text.length();
        for (int i = 0; i < length; i++)
            stringBuffer.append(text.charAt(i) + "\n");
    }//  w w  w  .ja v a  2  s. c o m
    stringBuffer.deleteCharAt(stringBuffer.lastIndexOf("\n"));
    return stringBuffer.toString();
}

From source file:Main.java

public static String string2HexString(String str) {

    StringBuffer hexString = new StringBuffer();
    for (int i = 0; i < str.length(); i++) {
        int ch = (int) str.charAt(i);
        String strHex = Integer.toHexString(ch);
        hexString.append(strHex);//www .ja  v a 2 s  . c  o m
    }
    return hexString.toString();

}

From source file:Main.java

public static String getRandomNum() {
    StringBuffer sb = new StringBuffer();
    Random random = new Random();
    for (int i = 0; i < 3; i++) {
        sb.append(random.nextInt(9));/*  w w w  .jav a  2s.  com*/
    }
    return sb.toString();
}

From source file:Main.java

private static String byteToHexString(byte[] digest) {
    StringBuffer hexString = new StringBuffer();
    for (int i = 0; i < digest.length; i++) {
        String hex = Integer.toHexString(digest[i] & 0xFF);
        if (hex.length() == 1) {
            hex = '0' + hex;
        }/*from   w ww. j a  v  a2 s.  c  o m*/
        hexString.append(hex.toUpperCase());
    }
    return hexString.toString();
}

From source file:Main.java

public static String arrayToString(Object[] array) {
    StringBuffer str = new StringBuffer();
    if (array.length > 1)
        str.append("{");
    for (int i = 0; i < array.length; i++) {
        if (i != 0)
            str.append(",");
        Object o = array[i];//from  w  w w . ja v  a2s  . c o  m
        str.append(safeToString(o));
    }
    if (array.length > 1)
        str.append("}");
    return str.toString();
}

From source file:Main.java

public static String listToString(List list) {
    StringBuffer sb = new StringBuffer();
    for (Object o : list) {
        sb.append(o.toString() + " ");
    }//  w  w  w. j  a va 2  s . c  o  m
    return sb.toString();
}

From source file:Main.java

public static String escape(String xmlstr) {
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < xmlstr.length(); i++) {
        char c = xmlstr.charAt(i);
        if (c == '&')
            buffer.append("&amp;");
        else if (c == '<')
            buffer.append("&lt;");
        else if (c == '>')
            buffer.append("&gt;");
        else if (c == '"')
            buffer.append("&quot;");
        else if (c == '\'')
            buffer.append("&apos;");
        else/*ww  w.  j  a va 2s  .c o m*/
            buffer.append(c);
    }
    return buffer.toString();
}