The moose likes Beginning Java and the fly likes Converting from a String to a StringBuffer Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Converting from a String to a StringBuffer" Watch "Converting from a String to a StringBuffer" New topic
Author

Converting from a String to a StringBuffer

Tom Patrick
Ranch Hand

Joined: Oct 24, 2000
Posts: 30
I know how to convert a StringBuffer into a String, but how do I do the reverse process?
Dean J
Greenhorn

Joined: Jan 28, 2001
Posts: 7
Just pass on the Stringbuffer object into String and create a new object.
String s = new String(stringBuffer);
vice versa use toString();
D.J
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6913
"Dean J",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please choose a new name which meets the requirements.
Thanks.


A Convergent Visionary ~ Frank's Punchbarrel Blog ~ LinkedIn profile
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6913
To get a String from a StringBuffer use the toString() method of the StringBuffer object.
To get a StringBuffer from a String, create a new StringBuffer with the String as its constructor argument.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Converting from a String to a StringBuffer
 
Similar Threads
How to convert StringBuffer to String ?
Cast from StringBuffer to String
a simple question
coversion of String buffer
regarding strings