Convert byte to String


public class Main {
    
    /**
     * Example method for converting a byte to a String.
     */
    public void convertByteToString() {
        
        byte b = 65;
        
        //Using the static toString method of the Byte class
        System.out.println(Byte.toString(b));

        //Using simple concatenation with an empty String
        System.out.println(b + "");
        
        //Creating a byte array and passing it to the String constructor
        System.out.println(new String(new byte[] {b}));
        
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new Main().convertByteToString();
    }
}

0 comments:

                                                                

Site Meter