Example usage for java.lang StringBuilder StringBuilder

List of usage examples for java.lang StringBuilder StringBuilder

Introduction

In this page you can find the example usage for java.lang StringBuilder StringBuilder.

Prototype

@HotSpotIntrinsicCandidate
public StringBuilder() 

Source Link

Document

Constructs a string builder with no characters in it and an initial capacity of 16 characters.

Usage

From source file:Main.java

public static String padLeft(String src, char c, int len) {
    StringBuilder s = new StringBuilder();
    for (int i = 0; i < len - src.length(); i++)
        s.append(c);//ww w .j  ava  2s .  c o m
    s.append(src);
    return s.toString();

}

From source file:Main.java

private static String convertToHexString(byte[] array) {
    StringBuilder hexStr = new StringBuilder();
    for (int i = 0; i < array.length; ++i) {
        hexStr.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3));
    }//from w w w .ja  v a 2 s . c  o m
    return hexStr.toString();
}

From source file:Main.java

public static String convert(String utfString) {
    StringBuilder sb = new StringBuilder();
    int i;//w ww  . j av a 2  s .c om
    int pos = 0;
    while ((i = utfString.indexOf("\\u", pos)) != -1) {
        sb.append(utfString.substring(pos, i));
        if (i + 5 < utfString.length()) {
            pos = i + 6;
            sb.append((char) Integer.parseInt(utfString.substring(i + 2, i + 6), 16));
        }
    }
    return sb.toString();
}

From source file:Main.java

public static String byteArrayToString(byte[] bytes) {
    StringBuilder sb = new StringBuilder();
    if (bytes == null)
        return "";
    for (int i = 0; i < bytes.length; i++) {
        sb.append(String.format("%02x", bytes[i]));
        sb.append(" ");
    }//from  w ww  . j a  v a2s.  co m
    return sb.toString().trim();
}

From source file:Main.java

public static String toHexString(byte[] bytes) {
    StringBuilder sign = new StringBuilder();
    for (int i = 0; i < bytes.length; i++) {
        String hex = Integer.toHexString(bytes[i] & 0xFF);
        if (hex.length() == 1) {
            sign.append("0");
        }/*  w w  w  . j  a v a  2s  .co  m*/
        sign.append(hex);
    }
    return sign.toString();
}

From source file:Main.java

public static String toHexString(byte[] bytes, String pad) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < bytes.length; i++) {
        sb.append(String.format("%02x%s", bytes[i], pad));
    }/*from  w ww .j  a  v  a2s . com*/
    return sb.toString();
}

From source file:Main.java

public static String encodeHexString(byte[] bytes) {
    StringBuilder buffer = new StringBuilder();
    encodeHexString(bytes, buffer);// w  w  w.  j  av  a2  s. c  o  m
    return buffer.toString();
}

From source file:Main.java

public static String byteToString(byte[] bytes) {
    StringBuilder sb = new StringBuilder();

    if (!isEmpty(bytes)) {
        for (int i = 0; i < bytes.length; i++) {
            sb.append(String.format("%02X", bytes[i]));
        }/*from ww  w  . j  a  va 2  s  . com*/
    }

    return sb.toString();
}

From source file:Main.java

private static void handlePluginException(Throwable throwable) {
    System.err.println((new StringBuilder()).append("RxJavaErrorHandler threw an Exception. It shouldn't. => ")
            .append(throwable.getMessage()).toString());
    throwable.printStackTrace();// ww  w. java 2s . c o m
}

From source file:Main.java

public static String asciiToHex(String ascii) {
    StringBuilder hex = new StringBuilder();

    for (int i = 0; i < ascii.length(); i++) {
        hex.append(Integer.toHexString(ascii.charAt(i)));
    }// ww w.j  a  v a 2s.c o  m
    return hex.toString();
}