List of usage examples for java.lang StringBuilder StringBuilder
@HotSpotIntrinsicCandidate
public StringBuilder()
From source file:Main.java
public static String getHexStr(byte[] b) { StringBuilder builder = new StringBuilder(); ByteArrayInputStream input = new ByteArrayInputStream(b); int i = 0;//from ww w . ja v a 2s . co m while ((i = input.read()) != -1) { builder.append( Integer.toHexString(i).length() == 2 ? Integer.toHexString(i) : 0 + Integer.toHexString(i)); builder.append(" "); } return builder.toString(); }
From source file:Main.java
public static String getRandomNumString(int length) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < length; i++) { builder.append(String.valueOf((int) (Math.random() * 10))); }/*from w ww . j av a2 s. c om*/ return builder.toString(); }
From source file:Main.java
public static String join(int... array) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < array.length; i++) { sb.append(array[i]);//from www .ja v a 2 s . co m if (i < array.length - 1) sb.append(','); } return sb.toString(); }
From source file:Main.java
public static String generateRandomStrs(int strCount) { StringBuilder randomStrs = new StringBuilder(); Random randomGenerator = new Random(); for (int i = 1; i < strCount; i++) { int randomInt = randomGenerator.nextInt(26); randomStrs.append((char) (randomInt + 'a')); }/* w w w . j a va 2 s.co m*/ return randomStrs.toString(); }
From source file:Main.java
public static String HdHrIpAddressToString(int ipAddress) { StringBuilder theBuilder = new StringBuilder(); byte[] theByteArray = HdHrIpAddressToByteArray(ipAddress); for (int i = 0; i < theByteArray.length; i++) { if (i == 0) { theBuilder.append("" + (int) (theByteArray[i] & 0xFF)); } else {/*w ww . j a v a2 s . c o m*/ theBuilder.append("." + (int) (theByteArray[i] & 0xFF)); } } return theBuilder.toString(); }
From source file:Main.java
public static <T> String listToString(List<T> list) { StringBuilder builder = new StringBuilder(); boolean firstCheck = true; for (T s : list) { if (firstCheck) { builder.append(s);/*from w ww. ja va 2 s. c o m*/ firstCheck = false; } else { builder.append(","); builder.append(s); } } return builder.toString(); }
From source file:Main.java
public static String join(Object[] words, String seperator) { StringBuilder sb = new StringBuilder(); if (words != null) { for (int i = 0; i < words.length; i++) { sb.append(words[i]);//from w w w.j av a 2s. co m if (i < words.length - 1) { sb.append(seperator); } } } return sb.toString(); }
From source file:Main.java
public static String join(Object[] words, String seperator) { StringBuilder sb = new StringBuilder(); if (words != null) { for (int i = 0; i < words.length; ++i) { sb.append(words[i]);/*from www . j av a 2s .c om*/ if (i < words.length - 1) { sb.append(seperator); } } } return sb.toString(); }
From source file:Main.java
public static String concat(String... texts) { final StringBuilder builder = new StringBuilder(); for (final String text : texts) { builder.append(text);//from ww w . j a v a 2 s .c o m } return builder.toString(); }
From source file:Main.java
private static String getToken(String json) { StringBuilder buf = new StringBuilder(); boolean isInYinHao = false; while (json.length() > 0) { String token = json.substring(0, 1); json = json.substring(1);//from w w w .j ava2s .c o m if (!isInYinHao && (token.equals(":") || token.equals("{") || token.equals("}") || token.equals("[") || token.equals("]") || token.equals(","))) { if (buf.toString().trim().length() == 0) { buf.append(token); } break; } if (token.equals("\\")) { buf.append(token); buf.append(json.substring(0, 1)); json = json.substring(1); continue; } if (token.equals("\"")) { buf.append(token); if (isInYinHao) { break; } else { isInYinHao = true; continue; } } buf.append(token); } return buf.toString(); }