How might I, in Java, convert a StringBuffer to a byte array?
A better alternate would be stringBuffer.toString().getBytes()
Better because String.valueOf(stringBuffer) in turn calls stringBuffer.toString(). Directly calling stringBuffer.toString().getBytes() would save you one function call and an equals comparison with null.
Here's the java.lang.String implementation of valueOf method:
public static String valueOf(Object obj) { return (obj == null) ? "null" : obj.toString(); }
I say we have an answer, from Greg:
String.valueOf(stringBuffer).getBytes()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With