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 replaceUpperCase(String str) {
    StringBuffer sb = new StringBuffer();
    String[] c = str.split("_");
    for (int i = 0; c != null && i < c.length; i++) {
        if (i > 0) {
            sb.append(c[i].substring(0, 1).toUpperCase() + c[i].substring(1));
        } else {// ww w  . j a v a  2s . c o  m
            sb.append(c[i]);
        }
    }
    return sb.toString();
}

From source file:Main.java

public static String replaceUpCase(String str) {
    StringBuffer sb = new StringBuffer();
    char[] c = str.toCharArray();
    for (int i = 0; c != null && i < c.length; i++) {
        if (i == 0) {
            sb.append(("" + c[i]).toUpperCase());
        } else if (c[i] < 97) {
            sb.append(("_" + c[i]));
        } else {//from   w  w w .  j  a v a 2 s. co m
            sb.append(c[i]);
        }
    }
    return sb.toString();
}

From source file:Main.java

public static String formatCardId(String cardId) {
    StringBuffer sb = new StringBuffer();

    if (cardId != null && cardId.length() > 0) {
        for (int i = 0; i < cardId.length(); i++) {
            sb.append(cardId.substring(i, i + 1));
            if (i >= 3 && (i - 3) % 4 == 0 && i != cardId.length() - 1) {
                sb.append(" ");
            }//from  w  w w . ja  v  a2 s  . c  o m
        }
    }

    return sb.toString();
}

From source file:Main.java

public static final void println(String... argvs) {
    StringBuffer mStringBuffer = new StringBuffer();
    for (String argv : argvs) {
        mStringBuffer.append(argv);/*from www  . j  av  a  2  s.c  o  m*/
        mStringBuffer.append(" ");
    }
    System.out.println(mStringBuffer.toString());
}

From source file:Main.java

public static String unicode2String(String unicodeStr) {
    StringBuffer sb = new StringBuffer();
    String str[] = unicodeStr.toUpperCase().split("U");
    for (int i = 0; i < str.length; i++) {
        if (str[i].equals(""))
            continue;
        char c = (char) Integer.parseInt(str[i].trim(), 16);
        sb.append(c);//from   ww  w.  j  av a  2s.c  om
    }
    return sb.toString();
}

From source file:Main.java

public static String join(String[] arry, String with) {
    StringBuffer buf = new StringBuffer();
    for (String s : arry) {
        if (buf.length() > 0) {
            buf.append(with);//w w w .  jav a 2 s . c  om
        }
        buf.append(s);
    }
    return buf.toString();
}

From source file:Main.java

public static String stringToAscii(String val) {
    StringBuffer stringBuffer = new StringBuffer();
    char[] chars = val.toCharArray();

    for (int i = 0; i < chars.length; i++) {
        stringBuffer.append((int) chars[i]);
    }/*from   ww w  . ja v  a  2  s.c  o m*/

    return stringBuffer.toString();
}

From source file:Main.java

private static String getDigitsOnly(String s) {
    StringBuffer digitsOnly = new StringBuffer();
    char c;//from w ww .  j av  a2s.c  om
    for (int i = 0; i < s.length(); i++) {
        c = s.charAt(i);
        if (Character.isDigit(c)) {
            digitsOnly.append(c);
        }
    }
    return digitsOnly.toString();
}

From source file:Main.java

public static String byte2hex(byte paramByte) {
    StringBuffer localStringBuffer = new StringBuffer();
    char[] arrayOfChar = { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70 };
    int i = (paramByte & 0xF0) >> 4;
    int j = paramByte & 0xF;
    localStringBuffer.append(arrayOfChar[i]);
    localStringBuffer.append(arrayOfChar[j]);
    return localStringBuffer.toString();
}

From source file:Main.java

static String convertToHex(byte[] data) {
    StringBuffer buf = new StringBuffer();

    for (int i = 0; i < data.length; i++) {
        int halfbyte = (data[i] >>> 4) & 0x0F;
        int two_halfs = 0;

        do {/* ww w.  ja  v a2s .  co  m*/
            if ((0 <= halfbyte) && (halfbyte <= 9)) {
                buf.append((char) ('0' + halfbyte));
            } else {
                buf.append((char) ('a' + (halfbyte - 10)));
            }

            halfbyte = data[i] & 0x0F;
        } while (two_halfs++ < 1);
    }
    return buf.toString();
}