Java – Create String from Byte Array
To create a String from byte array in Java, create a new String object with String() constructor and pass the byte array as argument to the constructor.
In the following example, we will take a byte array {65, 66, 67, 68}
and create a new string str
from this byte array.
Java Program
public class Example { public static void main(String[] args) { byte arr[] = {65, 66, 67, 68}; String str = new String(arr); System.out.println("Resulting string is : " + str); } }
ADVERTISEMENT
Output
Resulting string is : ABCD
Conclusion
In this Java Tutorial, we learned how to create a String from byte array.