Convert byte value to string value
Two methods we can use to convert a byte value to a string value. First method is the toString method from Byte class
String toString()
- Returns a String object representing this Byte's value.
public class Main {
public static void main(String[] args) {
Byte byteObject = new Byte("10");
String str = byteObject.toString();
System.out.println("str:"+str);
}
}
The outputs:
str:10
Another way is to use the static method toString(byte b).
static String toString(byte b)
- Returns a new String object representing the specified byte.
public class Main {
public static void main(String[] args) {
byte b = 10;
System.out.println("str:"+Byte.toString(b));
}
}
The output:
str:10