java - Is there a Character.toChar? -
i know can use character.tochars char[] codepoint. far have:
public static string bytestostring(byte[] bytes) { char[] buffer = new char[bytes.length]; int = 0; (byte abyte : bytes) { buffer[i] = character.tochars(abyte)[0]; i++; } return new string(buffer); }
and works. rather skip char[] , go straight char. every time search have above. hoping little cleaner.
the code have best you're going find if intend use character class. , in honesty -- doesn't messy. i'd stick it.
the entire method unnecessary, however. string class has constructor can turn array of bytes string.
string(byte[] bytes, charset charset)
use this:
string str = new string(bytes, standardcharsets.utf_8);
Comments
Post a Comment