List of usage examples for java.lang StringBuilder length
int length();
From source file:me.st28.flexseries.flexcore.util.ArrayUtils.java
/** * Converts a string array into a string, with a configurable delimiter. * * @param delimiter What to use to separate each value of the string array. */// ww w . j av a 2 s . co m public static String stringArrayToString(String[] array, String delimiter) { Validate.notNull(array); Validate.notNull(delimiter); StringBuilder sb = new StringBuilder(); for (String str : array) { if (sb.length() > 0) { sb.append(delimiter); } sb.append(str); } return sb.toString(); }
From source file:Main.java
public static String join(String[] track) { StringBuilder buf = new StringBuilder(11 * track.length); for (String str : track) { if (0 != buf.length()) { buf.append(","); }//w ww . ja v a 2s .c o m buf.append(str); } return buf.toString(); }
From source file:Main.java
public static final String mapToQueryString(HashMap<String, String> queryString) { StringBuilder sb = new StringBuilder(); try {//ww w .ja v a 2 s. c om for (HashMap.Entry<String, String> e : queryString.entrySet()) { if (sb.length() > 0) { sb.append('&'); } sb.append(URLEncoder.encode(e.getKey(), "UTF-8")).append('=') .append(URLEncoder.encode(e.getValue(), "UTF-8")); } } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } return sb.toString(); }
From source file:Main.java
public static String getFileAsString(File file) { try {/* w ww. j a va 2s .c o m*/ FileInputStream fin = new FileInputStream(file); BufferedReader reader = new BufferedReader(new InputStreamReader(fin, "UTF-8")); StringBuilder sb = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { if (sb.length() > 0) { sb.append("\n"); } sb.append(line); } reader.close(); fin.close(); return sb.toString(); } catch (Exception e) { return null; } }
From source file:Main.java
public static String replace(String str, String[] targets, String[] replacements) { StringBuilder sb = new StringBuilder(str); int index, lenTarget; for (int i = 0; i < targets.length; i++) { index = sb.length(); lenTarget = targets[i].length(); while ((index = sb.lastIndexOf(targets[i], index)) != -1) { sb.replace(index, index + lenTarget, replacements[i]); index -= lenTarget;// w ww. j a va 2s . com } } return sb.toString(); }
From source file:Main.java
private static String formatAddress(byte[] addr) { StringBuilder buf = new StringBuilder(24); for (byte b : addr) { buf.append(String.format("%02x:", b & 0xff)); }//w w w . j a va 2s .co m return buf.substring(0, buf.length() - 1); }
From source file:Main.java
public static String convertMaskedPhone(String phone) { StringBuilder phoneNumber = new StringBuilder(phone); for (int i = 0; i < phoneNumber.length(); i++) { switch (Character.toLowerCase(phoneNumber.charAt(i))) { case 'a': case 'b': case 'c': phoneNumber.setCharAt(i, '2'); break; case 'd': case 'e': case 'f': phoneNumber.setCharAt(i, '3'); break; case 'g': case 'h': case 'i': phoneNumber.setCharAt(i, '4'); break; case 'j': case 'k': case 'l': phoneNumber.setCharAt(i, '5'); break; case 'm': case 'n': case 'o': phoneNumber.setCharAt(i, '6'); break; case 'p': case 'q': case 'r': case 's': phoneNumber.setCharAt(i, '7'); break; case 't': case 'u': case 'v': phoneNumber.setCharAt(i, '8'); break; case 'w': case 'x': case 'y': case 'z': phoneNumber.setCharAt(i, '9'); break; case '+': phoneNumber.setCharAt(i, '0'); break; }// www. java 2 s . c om } return phoneNumber.toString(); }
From source file:Main.java
public static String join(int[] follows) { StringBuilder buf = new StringBuilder(11 * follows.length); for (int follow : follows) { if (0 != buf.length()) { buf.append(","); }/* w w w .ja va 2 s .c o m*/ buf.append(follow); } return buf.toString(); }
From source file:Main.java
public static String join(long[] follows) { StringBuilder buf = new StringBuilder(11 * follows.length); for (long follow : follows) { if (0 != buf.length()) { buf.append(","); }/*from w w w. jav a2 s.co m*/ buf.append(follow); } return buf.toString(); }
From source file:Main.java
public static String stringify(Object[] array) { if (isEmpty(array)) { return ""; } else {/* w w w . jav a2 s . c o m*/ StringBuilder sb = new StringBuilder("{ "); for (Object obj : array) sb.append(obj).append(", "); return sb.deleteCharAt(sb.length() - 2).append("}").toString(); } }