Convert bytes to a string in java

Java 8Object Oriented ProgrammingProgramming

Use String(byte[]) constructor to convert byte[] to String.

Example

public class Tester {
   public static void main(String[] args) {
      String test = "I love learning Java";
      byte[] bytes = test.getBytes();
      String converted = new String(bytes);
      System.out.println(converted);
   }
}

Output

I love learning Java
raja
Published on 06-Feb-2018 12:49:11
Advertisements