The byteValue() method of Integer class of java.lang package converts the given Integer into a byte after a narrowing primitive conversion and returns it (value of integer object as a byte). Also, remember this method does override byteValue() method of the Number class.
The package view is as follows:
--> java.lang Package
--> Integer Class
--> byteValue() Method
Syntax :
public byte byteValue()
Return Type: Returns the numeric value represented by this object after conversion to byte type.
Note: It is compatible with Java 1.5 and onwards.
Example 1:
Java
import java.lang.Integer;
class GFG {
public static void main(String args[]) {
Integer a = new Integer( 34 );
byte b = a.byteValue();
System.out.println(b);
}
}
|
Example 2:
Java
import java.lang.*;
import java.util.*;
class GFG {
public static void main(String[] args)
{
Byte b = new Byte( "01" );
Byte bp = b.byteValue();
System.out.println( "Byte object : " + b);
String str
= "Primitive byte value of Byte object : " + bp;
System.out.println(str);
}
}
|
Output:Byte object : 1
Primitive byte value of Byte object : 1