Java Program to convert string to byte

Java 8Object Oriented ProgrammingProgramming

Use the valueOf() method to convert string to byte. Firstly, let us take a string.

String str = "65";

Now, use the valueOf() method to convert string to byte.

byte res = Byte.valueOf(str);

Let us see the complete example.

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      String str = "65";
      System.out.println("String: "+str);
      byte res = Byte.valueOf(str);
      System.out.println("Byte: "+res);
   }
}

Output

String: 65
Byte: 65
raja
Published on 12-Nov-2018 17:08:35
Advertisements