In: Computer Science
You are given a string literal “CS3360” Describe what is Stringbuilder class, 3 member methods in Stringbuilder class and use the above literal to show output of 3 methods.
StringBuilder
It is class present in java.lang package which represents mutable sequence of characters and it provides no guarantee of synchronization
Methods
1) length()- this method returns length of sequence
2) reverse()- this method reverses the given sequence
3) deleteCharAt()- this method removes the character at speciified
position in sequence
Program
class StringBuilderDemo
{
public static void main(String[] args)
{
String input="CS3360";
StringBuilder builder=new StringBuilder(input);
System.out.println("After reversing sequence
"+builder.reverse());
System.out.println("Length of sequence "+builder.length());
System.out.println("After deleting character at 2nd position
resultant sequence "+builder.deleteCharAt(1));
}
}
Output