List of usage examples for java.lang StringBuilder delete
@Override public StringBuilder delete(int start, int end)
From source file:Main.java
public static String implode(Iterable it, String glue) { StringBuilder result = new StringBuilder(); for (Object o : it) { result.append(glue).append(o);//from www .j a v a 2 s. c om } if (result.length() > 0) { result.delete(0, glue.length()); } return result.toString(); }
From source file:Main.java
public static String arrayToString(String message, ArrayList<Integer> arr) { StringBuilder resString = new StringBuilder(); resString.append(message);//from w w w.j a v a 2 s.co m for (int i : arr) { resString.append(i + 1).append(", "); } resString.delete(resString.length() - 2, resString.length()); return resString.toString(); }
From source file:Main.java
public static String appendWithSeparator(final Collection<?> items, final String sep, final boolean separatorAtEnd) { StringBuilder sb = new StringBuilder(); for (Object o : items) { sb.append(o.toString());/*from ww w. ja va 2 s .c o m*/ sb.append(sep); } if (sb.length() > 0 && !separatorAtEnd) { sb.delete(sb.length() - sep.length(), sb.length()); } 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; }// w w w .jav a 2s.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:hr.fer.spocc.export.DotExporter.java
private static void reduceTreePrefix(StringBuilder prefix) { int index = prefix.lastIndexOf("."); if (index != -1) prefix.delete(index, prefix.length()); }
From source file:Main.java
public static <T> String concatenate(String separator, T... values) { StringBuilder builder = new StringBuilder(); if (values != null) { for (T value : values) { builder.append(separator).append(value.toString()); }// w w w . j a v a 2 s. c om builder.delete(0, separator.length()); } return builder.toString(); }
From source file:Main.java
/** * For logging.//from w ww . ja v a 2s .c o m * * @param arr * @return */ public static <T> String array2str(T[] arr) { StringBuilder sb = new StringBuilder("["); try { if (arr != null && arr.length > 0) { for (T elem : arr) { sb.append(elem.toString()).append(", "); } sb.delete(sb.length() - 2, sb.length()); } sb.append("]"); } catch (Exception e) { } return sb.toString(); }
From source file:Main.java
public static String join(Collection<? extends Object> list, String separator) { StringBuilder sb = new StringBuilder(); for (Object o : list) { sb.append(o.toString());//from ww w. ja v a 2 s. c om sb.append(separator); } if (sb.length() > 0 && separator.length() > 0) { sb.delete(sb.length() - separator.length(), sb.length()); } return sb.toString(); }
From source file:Main.java
/** * For logging, extremely unnecessary.//w w w. ja v a 2 s. c o m * * @param list * @return */ public static <T> String list2str(List<T> list) { StringBuilder sb = new StringBuilder(); if (list != null && !list.isEmpty()) { sb.append("["); for (T t : list) { sb.append(t.toString()).append(", "); } sb.delete(sb.length() - 2, sb.length()); sb.append("]"); } return sb.toString(); }
From source file:Main.java
public static String decodePath(String path, String delimiter, String characterSet) throws UnsupportedEncodingException { final StringTokenizer tokenizer = new StringTokenizer(path, delimiter); final StringBuilder builder = new StringBuilder(path.length()); while (tokenizer.hasMoreTokens()) { builder.append(URLDecoder.decode(tokenizer.nextToken(), characterSet)); builder.append(delimiter);/*from w w w . j a v a 2 s. c o m*/ } builder.delete(builder.length() - delimiter.length(), builder.length()); return builder.toString(); }