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 generatePostID(String title, String date) {
    start++;/*from  w w  w.  j a v  a  2 s . co  m*/
    StringBuffer result = new StringBuffer();
    result.append(title).append(date).append(start);
    return result.toString();
}

From source file:Main.java

public static String byteToPdu(int b) {
    StringBuffer sb = new StringBuffer();
    String s = Integer.toHexString(b & 0xFF);
    if (s.length() == 1) {
        sb.append("0");
    }//from  w  ww.  j a  v  a 2  s  .  c o m
    sb.append(s);
    return sb.toString().toUpperCase();
}

From source file:Main.java

public static String generateGroupID(String title, String date) {
    start++;//from   w  w w . jav a  2 s.  co m
    StringBuffer result = new StringBuffer();
    result.append(title).append(date).append(start);
    return result.toString();
}

From source file:Main.java

public static String toXML(Object obj) {
    StringBuffer xml = new StringBuffer();
    StringBuffer space = new StringBuffer();
    toXMLCycle(obj, xml, space);//from  w  w  w  .ja v  a 2s . c o  m

    StringBuffer result = new StringBuffer();
    result.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
    result.append(
            "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\r\n");
    result.append("<plist version=\"1.0\">\r\n");
    result.append(xml);
    return result.toString();
}

From source file:Main.java

public static String join(final ArrayList<String> array, String separator) {
    StringBuffer result = new StringBuffer();
    if (array != null && array.size() > 0) {
        for (String str : array) {
            result.append(str);//from  w  w w.  j av  a 2 s.  c om
            result.append(separator);
        }
        result.delete(result.length() - 1, result.length());
    }
    return result.toString();
}

From source file:Main.java

public static String fillStringByBytesOnTail(String strValue, char ch, int iSign) {
    try {//from   ww  w .jav  a  2s. com
        StringBuffer strTemp = new StringBuffer();
        strTemp.append(strValue);
        int iDifference = iSign - strValue.getBytes().length;
        if (iDifference <= 0)
            return strValue;
        for (int i = 0; i < iDifference; i++)
            strTemp.append(ch);
        return strTemp.toString();
    } catch (Exception ex) {
        return "";
    }
}

From source file:Main.java

public static String getThreadStack(Thread t) {
    StackTraceElement[] stacks = t.getStackTrace();
    StringBuffer buffer = new StringBuffer();
    for (StackTraceElement stack : stacks) {
        String filename = stack.getFileName();
        if (filename == null) {
            filename = "NULL";
        }/*from  w ww.j av  a2  s .  co  m*/
        String className = stack.getClassName();
        String methodName = stack.getMethodName();
        int line = stack.getLineNumber();
        buffer.append(String.format("%s.%s(%s:%d)\r", className, methodName, filename, line));
    }
    return buffer.toString();
}

From source file:Main.java

public static String join(Object... objs) {
    if (objs == null)
        return "";
    StringBuffer s = new StringBuffer();
    for (int i = 0, n = objs.length; i < n; i++) {
        s.append(objs[i]);/*w w w .  jav  a 2s.c  o  m*/
        if (i != n - 1)
            s.append(",");
    }
    return s.toString();
}

From source file:Main.java

public static Method getGetMethod(Class<?> objectClass, String fieldName) {
    StringBuffer sb = new StringBuffer();
    sb.append("get");
    sb.append(fieldName.substring(0, 1).toUpperCase());
    sb.append(fieldName.substring(1));//from  w ww.j  av a  2  s.  com
    try {
        return objectClass.getMethod(sb.toString());
    } catch (Exception e) {
    }
    return null;
}

From source file:Main.java

public static String appendPercentSymbol(int percent) {

    StringBuffer sb;/*w w w . j  ava 2 s.c o  m*/

    sb = new StringBuffer();
    sb.append(percent);
    sb.append("%");

    return sb.toString();
}