Java Program to convert byte to string


In Java, there are different ways to convert byte to string.

Using toString() method, you can easily convert byte to string as shown below −

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      byte res = 87;
      // byte to string
      System.out.println(Byte.toString(res));
   }
}

Output

87

In the above example, we have taken a byte value.

byte res = 87;

With that, to convert to string, the method toString() is used as shown below −

Byte.toString(res);

Let us see another example to convert byte to string.

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      byte val = 77;
      System.out.println(new String(new byte[] {val}));
   }
}

Output

M

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 26-Jun-2020

390 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements