English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Java program converts a byte to a string

In Java, there are several methods to convert bytes to strings.

UsingtoString()Method, you can easily convert bytes to strings as shown below-

Example

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

Output Result

87

In the above example, we took a byte value.

byte res = 87;

Thus, to convert to a string, use the following methodtoString()As shown below-

Byte.toString(res);

Let's see another example of converting a byte to a string.

Example

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

Output Result

M