English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Convert byte to numeric primitive data type in Java

To convert Byte to a numeric primitive data type, use the following methods-

byteValue()
shortValue()
intValue()
longValue()
floatValue()

First, let's declare a byte.

Byte byteVal = new Byte("35

Now, let's look at a simple example of how to convert it to the long type.

long longVal = byteVal.longValue();
System.out.println(longVal);

In the same way, you can convert it to other primitive data types as shown in the following complete example-

Example

public class Demo {
   public static void main(String args[]) {
      //byte
     byte byteVal = new byte("35
     byte b = byteVal.byteValue();
      System.out.println(b);
      short shortVal = byteVal.shortValue();
      System.out.println(shortVal);
      int intVal = byteVal.intValue();
      System.out.println(intVal);
      long longVal = byteVal.longValue();
      System.out.println(longVal);
      float floatVal = byteVal.floatValue();
      System.out.println(floatVal);
      double doubleVal = byteVal.doubleValue();
      System.out.println(doubleVal);
   }
}

Output Result

35
35
35
35
35.0
35.0