Java program to convert byte to string

Initialize a string variable with a string value, convert it into bytes and again convert it back to a string , print it.


Input String is : I am !
Input String in byte format is : [B@106d69c
Byte to string format : I am !

Java Implementation:

import java.util.*;
import java.lang.*;

class CodeRegister
 public static void main (String[] args) throws java.lang.Exception
  String str = "I am !";
  byte[] bytes = str.getBytes();
  System.out.println("Input String is : "+str);
  System.out.println("Input String in byte format is : "+bytes);
  //converting from bytes to string again
  String toString = new String(bytes);
  System.out.println("Byte to string format : "+toString );