Java Number - byteValue() Method
The java.lang.Number.byteValue() method returns the value of the specified number as a byte, which may involve rounding or truncation. This implementation returns the result of intValue() cast to a byte.
Syntax
public byte byteValue()
Parameters
No parameter is required.
Return Value
Returns the numeric value represented by this object after conversion to type byte.
Exception
NA.
Example:
In the example below, the java.lang.Number.byteValue() method returns the byte value of the given numbers.
import java.lang.*; public class MyClass { public static void main(String[] args) { //creating an Integer value Integer val1 = 123; //creating a Float value Float val2 = 55.75f; //printing the byte value of given numbers System.out.println("byte value of val1: " + val1.byteValue()); System.out.println("byte value of val2: " + val2.byteValue()); } }
The output of the above code will be:
byte value of val1: 123 byte value of val2: 55
❮ Java.lang - Number