Skip to main content

Problem with StringBuffer.setLength

No replies
julraj
Offline
Joined: 2005-12-27
Points: 0

Hello,
I have the following program which doesn't execute the code after sf.toString(). It executes the code if I add the trim method. But I need to print nulls to match 80 characters.

class TestString
{
public static void main(String[] args)
{
String a = new String("test");
String d="test";
String f="Test";
String e="test";
String b = new String("Test");
StringBuffer sf = new StringBuffer("Rajan");
System.out.println("The string buffer length is " + sf.length());
sf.setLength(13);
System.out.println(sf.toString());
System.out.println("The string buffer length is " + sf.length());
String c=a;
System.out.println("The string == method returned " +(a ==b));
System.out.println("The string == method returned " +(a ==c));
System.out.println("The string == method returned " + (d ==e));
System.out.println("The string equals method returned " + a.equals(b));
System.out.println("The compare method method returned " +(a.compareTo(f)));

}
}