A)
-> java.lang.StringBuffer and java.lang.StringBuilder represent mutable string in java.
->whenever modification of string is more in the application we go for mutable strings.
->StringBuffer API and StringBuilder API is the same.
->StringBuffer is thread safe. i.e. all its methods are synchronized where as StringBuilder is not thread safe. i.e. none of its methods are synchronized for performance reasons Stringbuilder has to be used for mutable Strings.
->insert , delete, reverse, append are few special methods of StringBuffer / Stringbuilder.
->we can convert a Stringbuffer and vice versa.
Ex:
Scanner s = new Scanner (System.in);
System.out.println(“Enter the word :”);
String str1 = s.next();
String str2= new String(str1);
if( str1.equals(str2))
System.out.println(“It is a palindrome”);
Else
System.out.println(“It is not”);
Comments
Post a Comment