List of usage examples for java.lang StringBuffer toString
@Override @HotSpotIntrinsicCandidate public synchronized String toString()
From source file:Main.java
public static String getRandomString(int length) { String str = "abcdefghigklmnopkrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ0123456789"; Random random = new Random(); StringBuffer sf = new StringBuffer(); for (int i = 0; i < length; i++) { int number = random.nextInt(62);//0~61 sf.append(str.charAt(number));//from w w w.j a v a 2 s . c om } return sf.toString(); }
From source file:Main.java
private static String bytesToHex(byte[] b) { char hexDigit[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; StringBuffer buf = new StringBuffer(); for (int j = 0; j < b.length; j++) { buf.append(hexDigit[(b[j] >> 4) & 0x0f]); buf.append(hexDigit[b[j] & 0x0f]); }//from www . ja v a 2s . c o m return buf.toString(); }
From source file:Main.java
public static String stringArrayToString(String[] array) { StringBuffer result = new StringBuffer(); for (int i = 0; i < array.length - 1; i++) { result.append(array[i]).append(TAB); }/* w ww . ja v a 2 s. com*/ result.append(array.length - 1); return result.toString(); }
From source file:Main.java
public static String join(String[] arry, String with) { StringBuffer buf = new StringBuffer(); for (String s : arry) { if (buf.length() > 0) { buf.append(with);/*from w w w . ja v a 2s . c o m*/ } buf.append(s); } return buf.toString(); }
From source file:Main.java
/** * Escape the String value to returns attribute valid value. * /* ww w. j a v a2s . co m*/ * @param s * @return */ private static String getEscaped(String s) { StringBuffer result = new StringBuffer(s.length() + 10); for (int i = 0; i < s.length(); ++i) appendEscapedChar(result, s.charAt(i)); return result.toString(); }
From source file:Main.java
public static String getNowDate() { StringBuffer sbBuffer = new StringBuffer(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); sbBuffer.append(format.format(Calendar.getInstance().getTime())); return sbBuffer.toString(); }
From source file:Main.java
public static String toHexString(byte[] __arr, String __s) { StringBuffer __res = new StringBuffer(); for (int i = 0; i < __arr.length; i++) { byte b = __arr[i]; __res.append(HEX[b & 0xFF] + __s); }/* w ww . ja v a 2s . c om*/ return __res.toString(); }
From source file:Main.java
public static String toHexString(byte b) { StringBuffer result = new StringBuffer(3); result.append(Integer.toString((b & 0xF0) >> 4, 16)); result.append(Integer.toString(b & 0x0F, 16)); return result.toString(); }
From source file:Main.java
/** * Remove xml comments from the xml string. * // w ww. java 2s .c o m * @param xml * @return */ public static String stripXMLComment(CharSequence xml) { if (xml == null) { return null; } // option DOTALL: '.' matches newlines // use '.+?' in stead of '.*': non-greedy matching ("<!-- --> <important-stuff\> <!-- -->" is replaced with " <important-stuff\> ") Pattern p = Pattern.compile("<!--.+?-->", Pattern.DOTALL); //$NON-NLS-1$ Matcher m = p.matcher(xml); StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, ""); //$NON-NLS-1$ } m.appendTail(sb); return sb.toString(); }
From source file:Main.java
public static String toCsv(String[] array) { StringBuffer result = new StringBuffer(); for (int s = 0; s < array.length; s++) { if (s > 0) result.append(", "); result.append(array[s]);//from www .j a va 2s .c o m } return result.toString(); }