Convert a String to a byte number in Java


Use the parseByte() method in Java to convert a String to a byte.

Let’s say the following is our string −

String str = “76”;

Now, the parseByte() method converts the string to byte −

byte val = Byte.parseByte(str);

The following is an example −

Example

 Live Demo

public class Demo {
    public static void main(String[] args) throws Exception {
       String str = "76";
       byte val = Byte.parseByte(str);
       System.out.println(val);
    }
}

Output

76

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 26-Jun-2020

142 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements