List of usage examples for java.lang StringBuffer toString
@Override @HotSpotIntrinsicCandidate public synchronized String toString()
From source file:Main.java
public static void main(String args[]) { StringBuffer buffer = new StringBuffer(); char charArray[] = { 'a', 'b', 'c', 'd', 'e', 'f' }; buffer.insert(0, charArray);// ww w . j av a 2s . c o m System.out.println(buffer.toString()); }
From source file:Main.java
public static void main(String args[]) { StringBuffer buffer = new StringBuffer(); char charArray[] = { 'a', 'b', 'c', 'd', 'e', 'f' }; buffer.insert(0, charArray, 3, 3);//w ww. jav a2 s . c om System.out.println(buffer.toString()); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { String hostname = "tock.usno.navy.mil"; Socket theSocket = new Socket(hostname, 13); InputStream timeStream = theSocket.getInputStream(); StringBuffer time = new StringBuffer(); int c;/* ww w. java 2 s .c o m*/ while ((c = timeStream.read()) != -1) time.append((char) c); String timeString = time.toString().trim(); System.out.println("It is " + timeString + " at " + hostname); }
From source file:MainClass.java
public static void main(String args[]) { String joke = "dog day daughter daut did do done date"; String regEx = "d"; Pattern doggone = Pattern.compile(regEx); Matcher m = doggone.matcher(joke); StringBuffer newJoke = new StringBuffer(); while (m.find()) m.appendReplacement(newJoke, "g"); m.appendTail(newJoke);/*from w w w. j a va 2s . c o m*/ System.out.println(newJoke.toString()); }
From source file:MainClass.java
public static void main(String[] av) { String joke = "dog " + "dogs"; String regEx = "dog"; Pattern doggone = Pattern.compile(regEx); Matcher m = doggone.matcher(joke); StringBuffer newJoke = new StringBuffer(); while (m.find()) { m.appendReplacement(newJoke, "goat"); }//from w w w . jav a2s .c o m m.appendTail(newJoke); System.out.println(newJoke.toString()); }
From source file:MainClass.java
public static void main(String[] args) { String hostname = "time.nist.gov"; try {/*from w w w . j a v a 2s.c o m*/ Socket theSocket = new Socket(hostname, 13); InputStream timeStream = theSocket.getInputStream(); StringBuffer time = new StringBuffer(); int c; while ((c = timeStream.read()) != -1) time.append((char) c); String timeString = time.toString().trim(); System.out.println("It is " + timeString + " at " + hostname); } // end try catch (UnknownHostException ex) { System.err.println(ex); } catch (IOException ex) { System.err.println(ex); } }
From source file:Main.java
public static void main(String args[]) { StringBuffer sb = new StringBuffer(); sb.ensureCapacity(100);/*from ww w . j a va 2 s. com*/ sb.append("java2s.com"); System.out.println(sb.capacity()); System.out.println(sb.length()); System.out.println(sb.toString()); }
From source file:StringsDemo.java
public static void main(String[] args) { String palindrome = "Dot saw I was Tod"; int len = palindrome.length(); StringBuffer dest = new StringBuffer(len); for (int i = (len - 1); i >= 0; i--) { dest.append(palindrome.charAt(i)); }/*from w w w .j a va 2 s . com*/ System.out.println(dest.toString()); }
From source file:RegexTest.java
public static void main(String[] args) { Pattern p = Pattern.compile(REGEX); Matcher m = p.matcher(INPUT); // get a matcher object StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, REPLACE); }//from w w w . j ava 2 s . c o m m.appendTail(sb); System.out.println(sb.toString()); }
From source file:Main.java
public static void main(String... args) throws IOException { URL url = new URL("http://java2s.com"); InputStream is = url.openStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); StringBuffer sb = new StringBuffer(); String line;/*from w ww . ja va 2 s .co m*/ while ((line = br.readLine()) != null) sb.append(line + System.lineSeparator()); br.close(); System.out.print(sb.toString()); }