List of usage examples for java.lang StringBuilder StringBuilder
@HotSpotIntrinsicCandidate
public StringBuilder()
From source file:Main.java
public static <T> String join(Iterable<T> collection, String conjunction) { StringBuilder sb = new StringBuilder(); boolean isFirst = true; for (T item : collection) { if (isFirst) { isFirst = false;// www. j a v a2s . c o m } else { sb.append(conjunction); } sb.append(item); } return sb.toString(); }
From source file:Main.java
public final static <K, V> String keyJoin(Map<K, V> map, String separator) { StringBuilder sb = new StringBuilder(); for (Map.Entry<K, V> entry : map.entrySet()) { sb.append(String.valueOf(entry.getKey())).append(separator); }// w w w .j a va2 s . co m return sb.toString().substring(0, sb.toString().length() - separator.length()); }
From source file:Main.java
private static String bytesToHexString(byte[] bytes) { StringBuilder sb = new StringBuilder(); for (byte aByte : bytes) { String hex = Integer.toHexString(255 & aByte); if (hex.length() == 1) { sb.append('0'); }/*from ww w.j a v a 2 s .co m*/ sb.append(hex); } return sb.toString(); }
From source file:Main.java
public static <T> String listToSqlString(List<T> list) { StringBuilder builder = new StringBuilder(); boolean firstCheck = true; for (T s : list) { if (firstCheck) { builder.append("'" + s + "'"); firstCheck = false;//from www.jav a 2s.c om } else { builder.append(","); builder.append("'" + s + "'"); } } return builder.toString(); }
From source file:Main.java
public static String makeStrs(char ch, int len) { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < len; ++i) { stringBuilder.append(ch);//w w w . j av a 2 s . co m } return stringBuilder.toString(); }
From source file:Main.java
static public String join(List<String> list, String conjunction) { StringBuilder sb = new StringBuilder(); boolean first = true; for (String item : list) { if (first) first = false;/*from ww w .j av a 2s . c o m*/ else sb.append(conjunction); sb.append(item); } return sb.toString(); }
From source file:Main.java
public static String generateMultiContentType(final String boundary, final String charset) { StringBuilder buffer = new StringBuilder(); buffer.append("multipart/form-data; boundary="); buffer.append(boundary);//from w ww . j a v a 2 s.co m if (charset != null) { buffer.append("; charset="); buffer.append(charset); } return buffer.toString(); }
From source file:Main.java
public static String join(List<String> values, String string) { StringBuilder sb = new StringBuilder(); int c = values.size(); for (String val : values) { if (c-- > 1) sb.append(val + string); else/*from w w w .j a v a 2 s. c o m*/ sb.append(val); } return sb.toString(); }
From source file:Main.java
public static String asHtmlBr(String prefix, List<String> strings) { StringBuilder s = new StringBuilder(); boolean first = true; for (String n : strings) { if (!first) s.append("<br/>"); s.append(prefix);//ww w . j ava2s.com s.append(n); first = false; } return s.toString(); }
From source file:Main.java
public static String join(Collection<String> c, String sep) { StringBuilder sb = new StringBuilder(); boolean seenFirst = false; for (String e : c) { if (seenFirst) { sb.append(sep);/*from ww w. j ava 2s . c o m*/ } else { seenFirst = true; } sb.append(e); } return sb.toString(); }