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 formatAccountNo(String accountNo) {
    try {// w  ww  .j a v a 2s.  com
        StringBuffer s = new StringBuffer();
        for (int i = 0; i < accountNo.length() - 10; i++) {
            s.append("*");
        }

        StringBuffer sb = new StringBuffer(accountNo);
        sb.replace(6, accountNo.length() - 4, s.toString());
        return sb.toString();
    } catch (Exception e) {
        return accountNo;
    }
}

From source file:Main.java

public static String createXml(Map<String, Object> map) {
    StringBuffer sb = new StringBuffer();
    for (String key : map.keySet()) {
        sb.append("<").append(key).append(">");
        sb.append(map.get(key));/*www .j  av  a2s . com*/
        sb.append("</").append(key).append(">");
    }
    return sb.toString();
}

From source file:Main.java

private static String buildURI(String host, String location, boolean isSecure) {
    StringBuffer uri = new StringBuffer();
    if (isSecure)
        uri.append("https://");
    else/*from  w w w  .ja va2  s .  c om*/
        uri.append("http://");

    uri.append(host);
    uri.append(location);
    return uri.toString();
}

From source file:Main.java

public static StringBuffer getTags(List<String> list) {
    StringBuffer buffer = new StringBuffer();
    if (list.size() == 0) {
        return buffer;
    }/*from  w w  w.j a v  a  2 s .  com*/
    for (int i = 0; i < list.size(); i++)
        buffer.append(list.get(i));
    return buffer;
}

From source file:Main.java

public static String GetDisplayTitle(String alias, String creditCode) {
    StringBuffer sb = new StringBuffer();
    if (alias != null && alias.trim() != "") {
        sb.append("[");
        sb.append(alias.trim());//from ww  w .  jav  a  2 s . c o  m
        sb.append("] ");
    }
    if (creditCode != null && creditCode.trim() != "") {
        if (creditCode.length() > 10) {
            sb.append(creditCode.substring(0, 6));
            sb.append("...");
            sb.append(creditCode.substring(creditCode.length() - 4, 4));
        } else
            sb.append(creditCode);
    }
    return sb.toString();
}

From source file:Main.java

private static String rebuildMsg(StackTraceElement stackTraceElement, String msg) {
    StringBuffer sb = new StringBuffer();
    sb.append(stackTraceElement.getFileName());
    sb.append(" (");
    sb.append(stackTraceElement.getLineNumber());
    sb.append(") ");
    sb.append(stackTraceElement.getMethodName());
    sb.append(": ");
    sb.append(msg);//from  w  ww . java2  s.  co m
    return sb.toString();
}

From source file:Utils.java

public static String getElementText(Element e) {
    StringBuffer buf = new StringBuffer();
    for (Node n = e.getFirstChild(); n != null; n = n.getNextSibling()) {
        if (n.getNodeType() == Node.TEXT_NODE || n.getNodeType() == Node.CDATA_SECTION_NODE) {
            buf.append(n.getNodeValue());
        }/*from  w ww  . j  av  a 2 s.  com*/
    }
    return buf.toString();
}

From source file:Main.java

public static String MapToUrl(Map<?, ?> data) {
    StringBuffer queryString = new StringBuffer();
    for (Map.Entry<?, ?> pair : data.entrySet()) {
        queryString.append(pair.getKey() + "=");
        queryString.append(pair.getValue() + "&");
    }//w ww. ja  v  a  2 s.  c  o m
    if (queryString.length() > 0) {
        queryString.deleteCharAt(queryString.length() - 1);
    }
    return queryString.toString();
}

From source file:Main.java

public static String getInviteNum(int uid) {

    String str = String.valueOf(uid);
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < 6 - str.length(); i++) {
        sb.append("0");
    }/* w ww .j  ava  2  s  . c  o m*/
    sb.append(str);
    return sb.toString();
}

From source file:Main.java

@SuppressWarnings("unused")
private static String parseByte2HexStr(byte buf[]) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < buf.length; i++) {
        String hex = Integer.toHexString(buf[i] & 0xFF);
        if (hex.length() == 1) {
            hex = '0' + hex;
        }/*from  ww  w.  ja v a  2 s .  c om*/
        sb.append(hex.toUpperCase());
    }
    return sb.toString();
}