List of usage examples for java.lang StringBuilder StringBuilder
@HotSpotIntrinsicCandidate
public StringBuilder()
From source file:Main.java
public static String leftPad(String source, int size, String s) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < size; i++) builder.append(s);//from w w w . jav a2s. c o m builder.append(source); return builder.toString(); }
From source file:Main.java
public static String parseTime(int ms) { StringBuilder builder = new StringBuilder(); int hour = ms / 1000 / 3600; if (hour < 10) { builder.append("0"); }//from w ww . j av a2s .c o m builder.append(hour); builder.append(":"); int minute = ms / 1000 % 3600 / 60; if (minute < 10) { builder.append("0"); } builder.append(minute); builder.append(":"); int second = ms / 1000 % 3600 % 60; if (second < 10) { builder.append("0"); } builder.append(second); return builder.toString(); }
From source file:Main.java
public static String bytesToHexString(byte[] src) { StringBuilder stringBuilder = new StringBuilder(); if (src == null || src.length <= 0) { return null; }/*from ww w .j a v a 2 s .c o m*/ char[] buffer = new char[2]; for (int i = 0; i < src.length; i++) { buffer[0] = Character.forDigit((src[i] >>> 4) & 0x0F, 16); buffer[1] = Character.forDigit(src[i] & 0x0F, 16); stringBuilder.append(buffer); } return stringBuilder.toString(); }
From source file:Main.java
public static String bytesToNoSpaceHexString(byte abyte0[]) { StringBuilder stringbuilder = new StringBuilder(); for (int i = 0; i < abyte0.length; i++) { stringbuilder.append(String.format("%02x", new Object[] { Byte.valueOf(abyte0[i]) })); }//from w w w .j a v a 2 s . co m return stringbuilder.toString(); }
From source file:Main.java
public static String floatArrayToStringWithRadToDeg(float[] array) { StringBuilder builder = new StringBuilder(); for (float v : array) { builder.append("" + 57.295776f * v + " "); }/*from ww w .j a v a2s. c o m*/ builder.append("\n"); return builder.toString(); }
From source file:Main.java
public static String join(String[] array, String delimiter) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < array.length; i++) { sb.append(array[i]);//from w w w . ja va2 s .c o m if (i < (array.length - 1)) { sb.append(delimiter); } } return sb.toString(); }
From source file:Main.java
public static <T> String join(T[] array, String cement) { StringBuilder builder = new StringBuilder(); if (array == null || array.length == 0) { return null; }//from w ww .j a v a2 s . co m for (T t : array) { builder.append(t).append(cement); } builder.delete(builder.length() - cement.length(), builder.length()); return builder.toString(); }
From source file:Main.java
private static String convertToMac(byte[] mac) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < mac.length; i++) { byte b = mac[i]; int value = 0; if (b >= 0 && b <= 16) { value = b;/* w w w. java2 s . c o m*/ sb.append("0" + Integer.toHexString(value)); } else if (b > 16) { value = b; sb.append(Integer.toHexString(value)); } else { value = 256 + b; sb.append(Integer.toHexString(value)); } if (i != mac.length - 1) { sb.append(":"); } } return sb.toString(); }
From source file:Main.java
public static String addStringsWithSpaces(Object... params) { StringBuilder stringBuilder = new StringBuilder(); for (Object s : params) { stringBuilder.append(s);//from ww w . j a v a2 s . c om stringBuilder.append(" "); } return stringBuilder.toString(); }
From source file:Main.java
public static String join(String seperator, String[] array) { StringBuilder sb = new StringBuilder(); if (array != null) { for (int i = 0; i < array.length; i++) { sb.append(array[i]);/*from w w w .j a v a2 s.c o m*/ if (i < array.length - 1) { sb.append(seperator); } } } return sb.toString(); }