Convert a String to a byte number in Java

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 12-Dec-2018 10:42:18
Advertisements