Is there a way to create a StringBuilder from a byte[]?
I want to improve memory usage using StringBuilder but what I have first is a byte[], so I have to create a String from the byte[] and then create the StringBuilder from the String and I don’t see this solution as optimal.
Thanks
Basically, your best option seems to be using CharsetDecoder directly.
Here’s how:
ADDED:
After some tests it seems that the simple
new String(bytes)is much faster and it seems there is no simple way to make it faster than that. Here is the test I ran:Results:
And a modified (less memory-consuming) version on IDEONE: Here.