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 KJdecipher(String str) {
    char[] cstr = str.toCharArray();
    StringBuilder hex = new StringBuilder();
    for (char c : cstr) {
        hex.append((char) (c - 5));
    }/*  w  w w.  j  av  a  2  s  . co m*/
    return hex.toString();
}

From source file:Main.java

public static String getHexArray(byte[] arr) {
    StringBuilder sb = new StringBuilder();
    for (byte c : arr) {
        sb.append(String.format("%02X ", c));
    }// w  w w  . j a v a 2  s .c o m
    return sb.toString();
}

From source file:Main.java

public static String getHead(String name) {
    char c = name.charAt(name.length() - 1);
    StringBuilder sb = new StringBuilder();
    sb.append(c);// w ww . j  a v a 2s .  co m
    return sb.toString();
}

From source file:Main.java

private static String byte2hex(byte[] b) {
    StringBuilder hs = new StringBuilder();
    String stmp;/*from   ww  w  .j a va 2s.  c om*/
    for (int n = 0; b != null && n < b.length; n++) {
        stmp = Integer.toHexString(b[n] & 0XFF);
        if (stmp.length() == 1)
            hs.append('0');
        hs.append(stmp);
    }
    return hs.toString().toUpperCase();
}

From source file:Main.java

public static String join(Collection<String> c, String sep) {
    StringBuilder sb = new StringBuilder();
    for (String str : c) {
        sb.append(str + sep);/*from w  w w  .  j a  v a2s  .  c  om*/
    }
    return sb.toString();
}

From source file:Main.java

public static String makeHtmlSpace(int number) {
    final String space = "&nbsp;";
    StringBuilder result = new StringBuilder();
    for (int i = 0; i < number; i++) {
        result.append(space);//from   w  ww  .jav  a 2s  .  c om
    }
    return result.toString();
}

From source file:Main.java

private static String appendColumnSpaces(String value, int columnWidth) {
    StringBuilder builder = new StringBuilder();
    int spaceCount;
    if (value == null) {
        builder.append("null");
        spaceCount = columnWidth - 4;//from w  w  w .  j a v  a2s.  c  o m
    } else {
        builder.append(value);
        spaceCount = columnWidth - value.length();
    }
    for (int i = 0; i < spaceCount; i++) {
        builder.append(" ");
    }
    return builder.toString();
}

From source file:Main.java

public static String getApplicationUserName(Context context, String s) {
    return (new StringBuilder()).append(s).append("_")
            .append(android.provider.Settings.Secure.getString(context.getContentResolver(), "android_id"))
            .toString();//from   www.j a  v a2s  .c o  m
}

From source file:Main.java

public static String toString(Collection<String> c) {
    StringBuilder sb = new StringBuilder();
    for (String s : c) {
        sb.append(s).append(",");
    }//from w  w w. j a v a2s  . c o m
    if (sb.toString().endsWith(",")) {
        return sb.substring(0, sb.length() - 1);
    } else {
        return sb.toString();
    }
}

From source file:Main.java

private static String _bytes2Hex(byte[] b) {
    StringBuilder builder = new StringBuilder();
    String stmp = "";

    for (int i = 0; i < b.length; i++) {
        stmp = Integer.toHexString(b[i] & 0xFF);
        if (stmp.length() == 1) {
            builder.append("0" + stmp);
        } else {/*from   w w  w.  ja v a2  s.  co  m*/
            builder.append(stmp);
        }
    }

    return builder.toString().toUpperCase(Locale.getDefault());
}