how-to

Working with String

How to work with String throught StringBuilder class

Class java.lang.StringBuilder is useful when your string is often changed - for example when you append some other string after it. In this situation is using of this class preferable to using String type.

/* -- create object */
    
StringBuilder str = new StringBuilder( "Initial" );
   
/* -- change string */
    
str.append( " - " );
    
for ( int i = 0; i<10; i++ ) {
  str.append( i );
}
    
System.out.println( str );
The output will be:
Initial - 0123456789