Easiest way to convert String to StringBuffer
Hello lads!
Im looking a way to easily convert String to StringBuffer for passing it to different methods.
If it were the other way, I would use
Code:
thisMethodTakesString(myStringBuffer.toString());
However, I have method that takes StringBuffer as an argument, but my variable is String.
Right now I'm doing
Code:
String str = "Hello Java-forums.org";
/* This is where it goes kinda complicated and messy */
StringBuffer sb = new StringBuffer(str);
thisMethodTakesStringBuffer(sb);
Is there any simple way to cast String -> StringBuffer without needing to write those needless lines of code?
Thanks.