Series: StringBuffer

StringBuffer Examples Screenshots Simple terms

insert() StringBuffer Example

java.lang.StringBuffer class comes with many methods to manipulate string. One of such methods is insert() overloaded 12 times taking different parameters. insert() StringBuffer is used to insert some data in the buffer. Observe the 12 overloaded methods of insert() StringBuffer: public synchronized java.lang.StringBuffer insert(int, java.lang.Object); public synchronized java.lang.StringBuffer insert(int, java.lang.String); public synchronized java.lang.StringBuffer insert(int, char[]); …

insert() StringBuffer Example Read More »

StringBuffer substring Java Pass By Reference

StringBuffer substring Java Pass By Reference Many petty methods exist with StringBuffer like substring(), setLength() and trimToSize() etc. These methods are not much used in regular programming. public class MiscellaneousMethods { public static void main(String args[]) { // using substring(), to extract part of a string StringBuffer buffer1 = new StringBuffer(“TajMahal”); String s1 = buffer1.substring(3); …

StringBuffer substring Java Pass By Reference Read More »

ensureCapacity() StringBuffer Example

ensureCapacity() StringBuffer method gives guarantee the existing capacity. It behaves in two ways depending on the argument passed to the method. If the argument of the method is less than the existing capacity, then there will be no change in existing capacity (observe, sb1 in the example). If the argument is greater than the existing …

ensureCapacity() StringBuffer Example Read More »