Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to convert StringBuffer to String ?

 
Sourav Satyajit Mishra
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,
i am facing the problem of converting a StringBuffer to String ?
how do i do it.....

Please help!!!
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The toString method returns a String object that represents the StringBuffer contents.
 
sameer meher
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try the following code:

StringBuffer sbuf = new StringBuffer("sameer");
String str = sbuf.toString();
System.out.println(str);

toString() will convert from StringBuffer to String object
 
Sourav Satyajit Mishra
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks people!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic