Use String constructor:
public String(byte bytes[], int offset, int length, Charset charset)
Example:
myObject.name = new String(byteArr, 0, 10, Charset.defaultCharset())
Remember that bytes and characters are different in Java, and you must specify the correct conversion using the Charset class to avoid unexpected results.
source share