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
Updated on: 2020-06-26T16:27:46+05:30

240 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements