Write a program that show working of different functions of String and
StringBuffer classs like setCharAt(), setLength(), append(), insert(), concat()and
equals().
public class Main
{
public static void main(String[] args) {
//setCharAt()
StringBuffer str= new StringBuffer("Computer");
str.setCharAt(7, '0');
//setLength()
str.setLength(10);
//append()
str.append("Science");
//insert()
str.insert(10,true);
//concat()
String s2=" of Science";
String s1="BCS ".concat(s2);
//equals()
StringBuffer sa = new StringBuffer("abd");
StringBuffer sb = new StringBuffer("abc");
System.out.println(sa.equals(sb));
}
}
Comments
Leave a comment