Alex Rivera | Logout

How to Reassign value of StringBuffer?

Asked 2010-04-07T11:10:57.660
17

How can we re assign the value of a StringBuffer or StringBuilder Variable?

StringBuffer sb=new StringBuffer("teststr");

Now i have to change the value of sb to "testString" without emptying the contents. I am looking at a method which can do this assignment directly without using separate memory allocation.I think we can do it only after emptying the contents.

Edit
Report

1 Answer

29
sb.setLength(0);
sb.append("testString");
answered 2010-04-07T17:35:49.120

Your Answer