Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Convert Between Byte Array and String in Java

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

import java.util.Arrays

String to Byte Array

byte[] bytes = "how are you".getBytes();
for(byte b : bytes){
    System.out.println(b);
}
104
111
119
32
97
114
101
32
121
111
117
null

Byte Array to String

byte[] bytes = "how are you".getBytes();
System.out.println(new String(bytes));
how are you
null