Java Program to convert byte[] array to String

Java 8Object Oriented ProgrammingProgramming

To convert byte[] to String, firstly let us declare and initialize a byte array.

// byte array
byte[] arr = new byte[] {78, 79, 33};

Now take a String and include the array in it.

String str = new String(arr);

Let us see the complete example to convert byte array to String.

Example

 Live Demo

public class Demo {
   public static void main(String args[]) {
      // byte array
      byte[] arr = new byte[] {78, 79, 33};
      String str = new String(arr);
      // string
      System.out.println("String = "+str);
   }
}

Output

String = NO!
raja
Published on 12-Nov-2018 16:52:38
Advertisements