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 int2ip(int ipInt) {
    StringBuilder sb = new StringBuilder();
    sb.append(ipInt & 0xFF).append(".");
    sb.append((ipInt >> 8) & 0xFF).append(".");
    sb.append((ipInt >> 16) & 0xFF).append(".");
    sb.append((ipInt >> 24) & 0xFF);
    return sb.toString();
}

From source file:Main.java

public static String numToK(String num) {
    StringBuilder sb = new StringBuilder();
    if (num.length() >= 5) {
        sb.append(num.substring(0, 2)).append("k");
        return sb.toString();
    } else {//from w ww  .j a v  a 2s .  c  o m
        return num;
    }
}

From source file:Main.java

public static String bytes2Hex(byte[] bytes) {
    StringBuilder sb = new StringBuilder();
    for (byte b : bytes) {
        sb.append(String.format("%02X ", b));
    }/*from  www. j av  a 2  s .  c  om*/
    return sb.toString();
}

From source file:Main.java

public static String getDurationStr(long duration) {
    StringBuilder sb = new StringBuilder();

    return sb.toString();
}

From source file:Main.java

public static String builder(String... array) {
    StringBuilder s = new StringBuilder();
    for (String str : array) {
        s.append(str);/*from w w  w  . j a va  2s .  co m*/
    }
    return s.toString();
}

From source file:Main.java

public static String reverse(String input) {
    StringBuilder output = new StringBuilder();
    for (int i = input.length() - 1; i >= 0; i--) {
        output.append(input.charAt(i));//from w  w w  .j a v a 2s .c  om
    }
    return output.toString();
}

From source file:Main.java

public static String _byteArrayToHex(byte[] a) {
    StringBuilder sb = new StringBuilder();
    for (byte b : a)
        sb.append(String.format("%02x-", b & 0xff));
    sb.deleteCharAt(sb.length() - 1);//from ww w. ja va 2s  .  c  om
    return sb.toString();
}

From source file:Main.java

public static String fromHexString(String hex) {
    StringBuilder str = new StringBuilder();
    for (int i = 0; i < hex.length(); i += 2) {
        str.append((char) Integer.parseInt(hex.substring(i, i + 2), 16));
    }//from  ww  w  . ja v a  2  s .  c  o  m
    return str.toString();
}

From source file:Main.java

static String createInSQL(int length) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < length;) {
        builder.append("?");
        if (++i < length) {
            builder.append(",");
        }/*  w  w  w . j a  v  a 2 s.co m*/
    }
    return builder.toString();
}

From source file:Main.java

public static String dateChange(String date) {
    StringBuilder sb = new StringBuilder();
    String[] dateStr = date.split("-");
    for (int i = 0; i < dateStr.length; i++) {
        sb.append(dateStr[i]);/*  w  w w .  j  a  va2  s  .  c  o m*/
    }
    return sb.toString();
}