toCharArray
is better. That way you don't have to deal with encoding. At least not in the normal case (except for characters outside of the Unicode BMP, which are encoded as two surrogate chars). Basically, if you don't have to deal with Chinese text, that's not a problem.
The conversion from a String
to a char
array is faster than toBytes()
: it's basically an array copy, without character encoding trouble. Internally, a String
contains a char[]
, and (at least for Java 7 and newer), not much else.
It's also faster to construct a String
back from a char
array than from a byte
array, because no character encoding is needed.