Convert Byte to String

In this chapter you will learn:

  1. How to convert byte value to string value

Convert byte value to string value

There are 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. 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.

The following two examples is showing how to convert byte value to string value.

public class Main {
  public static void main(String[] args) {
    Byte byteObject = new Byte("10");
   //from  j  a  v  a2  s. c o  m
    String str = byteObject.toString();

The outputs:

The code below calls the static method to do the conversion.

public class Main {
  public static void main(String[] args) {
    //from ja  v  a 2  s .c  o  m
    byte b = 10;


The output:

We can also convert byte to String by concatenating byte value with an empty String.

public class Main {
    public static void main(String[] args) {
        byte b = 65;
        //from   ja  v a2 s  . c  om
        System.out.println(b + "");


The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. How to decode a string to a byte
  2. How to convert string value to byte value
  3. How to convert string to byte with radix
  4. java.lang.NumberFormatException when byte value is out of range
Home » Java Tutorial » Primitive Data Types


    Java Primitive Data Types


    Java boolean type
    Java boolean type conversion
    Convert string value to boolean
    Convert boolean to string


    Java char type
    Compare two char values
    Change char case
    Java char conversion
    Java char value and its attributes


    Java byte type
    Convert Byte to String
    Convert String to byte
    Byte object constructor
    Byte's max and min value
    Compare two byte values
    Convert Byte to byte, double, float, int, long and short


    Java short type
    Short min/max value and size
    Create Short object
    Compare short values
    Convert short to String
    Convert Short to primitive types
    Convert string to short
    Reverse bytes


    Java int type
    int max/min value
    Create Java integer
    Convert int to binary, hexadecimal and octal format
    Compare integer values
    Integer sign
    Convert string to int
    Convert int to primitive types
    Convert int to String
    int bit operations


    Java long type
    Compare two long values
    Convert long to binary, hex and octal
    Convert long value to primitive types
    Convert String to long value
    Convert long to String


    Java float type
    Java float type conversion
    Predefined value for float type
    Compare two float value


    Java double type
    Deal with NaN double value
    Compare two double values
    Java double type creation and comparison
    Java double type conversion

Data Type Conversion

    Java Automatic Type Conversion and Casting
    Data type casting
    Java type promotion
    Autoboxing and auto-unboxing