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 getTime() {
    StringBuffer sb = new StringBuffer();
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(System.currentTimeMillis());
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minutes = c.get(Calendar.MINUTE);
    if (hour < 10) {
        sb.append(0);/*w w w.ja  v a 2  s .c  om*/
        sb.append(hour);
    } else {
        sb.append(hour);
    }
    sb.append(':');
    if (minutes < 10) {
        sb.append(0);
        sb.append(minutes);
    } else {
        sb.append(minutes);
    }
    return sb.toString();

}

From source file:Main.java

public static String get_recv_data_str(byte[] rcv_buff, int len) {
    int i;//from  ww w  .  j  a  v a2s. c om

    StringBuffer sb = new StringBuffer();
    for (i = 0; i < len; i++) {
        if ((0x00f0 & ((char) rcv_buff[i])) == 0)
            sb.append(0);
        sb.append(Integer.toHexString(0x00ff & ((char) rcv_buff[i])).toUpperCase());
        //            if((i+1)%16 == 0) sb.append("\r\n");
    }
    String s = sb.toString();
    return s;
}

From source file:Main.java

public static String getFieldName(Vector vtNameStack) {
    StringBuffer strFieldName = new StringBuffer();
    for (int iIndex = 0; iIndex < vtNameStack.size(); iIndex++) {
        strFieldName.append('.');
        strFieldName.append((String) vtNameStack.elementAt(iIndex));
    }//from w w w  .  j  a  va2  s. com
    if (strFieldName.length() > 0)
        strFieldName.delete(0, 1);
    return strFieldName.toString();
}

From source file:Main.java

public static String timeFormatToString(int relTime) {
    StringBuffer timeBuf = new StringBuffer();
    relTime /= 1000;/*from   w ww. ja va 2s.  c o  m*/
    int time = relTime / 3600;
    if (time >= 10) {
        timeBuf.append(time);
    } else {
        timeBuf.append("0").append(time);
    }

    relTime %= 3600;
    time = relTime / 60;
    if (time >= 10) {
        timeBuf.append(":").append(time);
    } else {
        timeBuf.append(":0").append(time);
    }

    time = relTime % 60;
    if (time >= 10) {
        timeBuf.append(":").append(time);
    } else {
        timeBuf.append(":0").append(time);
    }

    return timeBuf.toString();
}

From source file:Main.java

public static String mapToJson(Map<String, Object> maps) {
    StringBuffer sb = new StringBuffer();
    int size = maps.size();
    int i = 0;/*  w w w  .java 2s  . c  o  m*/
    sb.append("{");
    for (String key : maps.keySet()) {
        i++;
        sb.append("\"" + key + "\"" + ":" + "\"" + maps.get(key) + "\"");
        if (i != size) {
            sb.append(",");
        }
    }
    sb.append("}");
    return sb + "";
}

From source file:Main.java

public static String convertListToURLParamsString(List<?> values) {
    StringBuffer buff = new StringBuffer();
    for (Object object : values) {
        buff.append(object.toString() + "&");
    }//from www. j a va2  s .com
    buff.replace(buff.length() - 1, buff.length(), "");
    return buff.toString();
}

From source file:Main.java

public static String cleanBlankToString(String des) {
    char[] chars = des.toCharArray();
    StringBuffer sb = new StringBuffer();
    for (Character c : chars) {
        if (java.util.regex.Pattern.matches("\\d", String.valueOf(c))) {
            sb.append(c);/*from   w  w w. j  a v a 2 s . c om*/
        }
    }
    return sb.toString();
}

From source file:Main.java

public static String getMapAppendUrl(Map<String, String> params) {
    StringBuffer sb1 = new StringBuffer();
    for (String key : params.keySet()) {
        sb1.append(key);/*from www  .ja va 2  s. c om*/
        sb1.append("=");
        sb1.append((String) params.get(key));
        sb1.append("&");
    }
    sb1.deleteCharAt(sb1.length() - 1);
    return sb1.toString();
}

From source file:Main.java

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   w  w  w  .  j  a va2 s. c  o m*/
        sb.append(hex.toUpperCase());
    }
    return sb.toString();
}

From source file:Main.java

public static String arrayStringConvertStr(Iterable<String> ids, String delimiter) {
    StringBuffer buffer = new StringBuffer();
    boolean first = true;
    for (String id : ids) {
        if (first) {
            buffer.append(id);//from   w  w  w.j a  v  a 2  s  . c  o m
            first = false;
        } else {
            buffer.append(delimiter).append(id);
        }
    }
    return buffer.toString();
}