Example of StringBuilder in Java
February 21, 2013
StringBuilder has come in java since jdk 1.5. StringBuilder is not synchronized. It cannot be used in multi-threaded
environment. StringBuffer can be used in multi-threaded environment. StringBuilder has the methods append, insert and appendCodePoint etc.
appendCodePoint can add character ASCI value with the string as
sb.appendCodePoint(90);
package com.concretepage; public class StringBuilderTest { public static void main(String... args) { StringBuilder sb = new StringBuilder("Hello"); //appends the string sb.append(" World"); //insert the string at specified place sb.insert(6, " Great_ "); //90 ASCI of Z, it is appended at the end sb.appendCodePoint(90); System.out.println(sb); //gets capacity of string builder object int c = sb.capacity(); System.out.println(c); } }
Hello Great_ WorldZ 21