String Buffer and String Builder Lyst5543
String Buffer and String Builder Lyst5543
StringBuffer Constructors:
● StringBuffer(): This creates an empty StringBuffer with a default capacity of 16
characters.
capacity.
string.
Output:
16
In the above code StringBuffer object is created by default 16 memory is
allocated.
Output:
Let’s see if you try to append the string more than the default capacity
public class Demo{
Output:
If the size is larger than the size of characters then you can reduce the storage
using trimToSize().
}
}
Output:
String Tokenizer:
start
true
false
hasMoreToken()
nextToken()
stop
import java.util.StringTokenizer;
while(st.hasMoreTokens()) {
System.out.println(st.nextToken());
}
}
}
Output: