The Wayback Machine - https://web.archive.org/web/20240920090750/https://www.geeksforgeeks.org/java-integer-bytevalue-method/
Open In App

Java Integer byteValue() Method

Last Updated : 06 May, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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




// Java program to Illustrate byteValue() Method
// Of Integer Class
 
// Importing required class
import java.lang.Integer;
 
// Main Class
class GFG {
 
    // Main driver method
    public static void main(String args[]) {
 
        // Creating an Integer object and
        // passing custom integer input
        Integer a = new Integer(34);
 
        // Converting integer number to byte value
        // using byteValue() method
        byte b = a.byteValue();
 
        // Printing the corresponding byte value
        System.out.println(b);
    }
}


Output:

34

Example 2:

Java




// Java Program to Illustrate byteValue() Method
// of Integer Class
 
// Importing required classes
import java.lang.*;
import java.util.*;
 
// Main Class
class GFG {
 
    // Main driver method
    public static void main(String[] args)
    {
 
        // Creating a Byte object
        Byte b = new Byte("01");
 
        // Converting Byte to byte primitive
        // using byteValue() method
        Byte bp = b.byteValue();
 
        // Display statement
        System.out.println("Byte object : " + b);
 
        // Primitive byte value of custom Byte passed above
        String str
            = "Primitive byte value of Byte object : " + bp;
 
        // Printing byte primitive value
        System.out.println(str);
    }
}


Output:

Byte object : 1
Primitive byte value of Byte object : 1


Similar Reads

Java lang.Long.byteValue() method in Java with Examples
java.lang.Long.byteValue() is a built-in function in Java that returns the value of this Long as a byte. Syntax: public byte byteValue() Parameters: The function does not accept any parameter. Return : This method returns the numeric value represented by this object after conversion to byte type. Examples: Input : 12 Output : 12 Input : 1023 Output
3 min read
Double byteValue() Method in Java with Examples
The java.lang.Double.byteValue() is a built-in method in Java that returns the value of this Double as a byte(by casting to a byte). Basically it used for narrowing primitive conversion of Double type to a byte value. Syntax: public byte byteValue() Parameters: The function does not accept any parameter. Return Value: This method returns the double
3 min read
Number.byteValue() Method in Java with Examples
The java.lang.Number.byteValue() is an inbuilt method in java that returns the value of the specified number as a byte. This may involve rounding or truncation. Syntax: public byte byteValue() Parameters: The method does not take any parameter. Return value: This method returns the numeric value represented by this object after conversion to type b
1 min read
Short byteValue() method in Java with Example
The java.lang.Short.byteValue() method of Short class is a built in method in Java which is used to return the value of the Short object as a byte. Syntax ShortObject.byteValue() Return Value: It return the value of ShortObject as byte. Below is the implementation of byteValue() method in Java: Example 1: // Java code to demonstrate // Short byteVa
2 min read
Float byteValue() method in Java with Examples
The java.lang.Float.byteValue() is a built-in method in Java that returns the value of this Float as a byte(by casting to a byte). Basically it used for narrowing primitive conversion of Float type to a byte value. Syntax: public byte byteValue() Parameters: The function does not accept any parameter. Return Value: This method returns the Float val
2 min read
Integer.MAX_VALUE and Integer.MIN_VALUE in Java with Examples
Most of the times, in competitive programming, there is a need to assign the variable, the maximum or minimum value that data type can hold, but remembering such a large and precise number comes out to be a difficult job. Therefore, Java has constants to represent these numbers, so that these can be directly assigned to the variable without actuall
3 min read
Integer.valueOf() vs Integer.parseInt() with Examples
Integer.parseInt():While operating upon strings, there are times when we need to convert a number represented as a string into an integer type. The method generally used to convert String to Integer in Java is parseInt(). This method belongs to Integer class in java.lang package. It takes a valid string as a parameter and parses it into primitive d
4 min read
Java Integer compareTo() method
The compareTo() method of Integer class of java.lang package compares two Integer objects numerically and returns the value 0 if this Integer is equal to the argument Integer; a value less than 0 if this Integer is numerically less than the argument Integer; and a value greater than 0 if this Integer is numerically greater than the argument Integer
2 min read
Java Integer compareUnsigned() method
The compareUnsigned() method of the Integer class of java.lang package compares two integer values (x, y) given as a parameter, treating the values as unsigned and returns the value zero if (x==y), if (x < y) then it returns a value less than zero, and if (x > y) then it returns a value greater than zero. Syntax: public static int compareUnsi
2 min read
Java Integer compare() method
The compare() method of Integer class of java.lang package compares two integer values (x, y) given as a parameter and returns the value zero if (x==y), if (x < y) then it returns a value less than zero and if (x > y) then it returns a value greater than zero. Syntax : public static int compare(int x, int y) Parameter : x : the first int to c
2 min read
Java lang.Integer.toBinaryString() method
The java.lang.Integer.toBinaryString() method returns a string representation of the integer argument as an unsigned integer in base 2. It accepts an argument in Int data-type and returns the corresponding binary string. Syntax: public static String toBinaryString(int num) Parameter : The function accepts a single mandatory parameter num num - This
1 min read
Java lang Integer.toHexString() Method with Examples
The Java.lang.Integer.toHexString() is a built-in function in Java which returns a string representation of the integer argument as an unsigned integer in base 16. The function accepts a single parameter as an argument in Integer data-type. Syntax : public static String toHexString(int num) Parameter : The function accepts a single mandatory parame
3 min read
Integer doubleValue() Method in Java
The doubleValue() method of Integer class of java.lang package is used to convert the value of the given Integer to a Double type after a widening primitive conversion and returns it. Syntax: public double doubleValue() Parameters: The method does not take any parameter. Return Value: This method returns a numeric value represented by this object a
1 min read
Integer.numberOfLeadingZeros() Method in Java With Example
The java.lang.Integer.numberOfLeadingZeros() is the method which returns the total number of zero(0) bits preceding the highest-order (ie.leftmost or most significant "1" bit)one-bit in the two's complement binary representation of the specified integer value or we can say that it is the function which converts int value to Binary then considers th
3 min read
Integer.numberOfTrailingZeros() Method in Java with Example
The Java.lang.Integer.numberOfTrailingZeros() is the method which returns the total number of zero(0) bits following the lowest-order (ie.Rightmost or least significant "1" bit)one-bit in the two's complement binary representation of the specified integer value or we can say that it is the function which converts int value to Binary then considers
3 min read
Integer hashCode() Method in Java
The java.lang.Integer.hashCode() method of Integer class in Java is used to return the hash code for a particular Integer . Syntax: public int hashCode() Parameters : The method does not take any parameters. Return Value: The method returns a hash code integer value for this object, which is equal to the uncomplicated primitive integer value, repre
2 min read
Integer decode() Method in Java
It is often seen that any integer within (" ") is also considered as string, then it is needed to decode that into the integer. The main function of java.lang.Integer.decode() method is to decode a String into an Integer. The method also accepts decimal, hexadecimal, and octal numbers. Syntax : public static Integer decode(String str) Parameters: T
2 min read
Integer lowestOneBit() Method in Java
The Integer.lowestOneBit() method of java.lang is an inbuilt function that returns an int value with at most a single one-bit, in the position of the lowest-order (ie.rightmost) one-bit in the specified int value. This method will return zero if the specified value has no one-bits in its two's complement binary representation, ie. if the binary rep
3 min read
Integer highestOneBit() Method in Java
The Integer.highestOneBit() method of java.lang returns an integer value with at most a single one-bit which is in the position of the highest-order (ie.leftmost) one-bit for the given int value. If the specified value has no one-bits in its two's complement binary representation then it returns zero, simply if it is equal to zero.Syntax: public st
3 min read
Integer reverse() Method In Java
The java.lang.Integer.reverse() is an inbuilt method in Java and is used to return the reverse order of the bits in the two's complement binary representation of the specified int value. Syntax: public static int reverse(int a) Parameters: The parameter a is an integer value whose bits are to be reversed. Return Value: The method returns the value
2 min read
Integer intValue() Method in Java
intValue() of Integer class that is present inside java.lang package is an inbuilt method in java that returns the value of this integer as an int which is inherited from Number Class. The package view is as follows: --> java.lang Package --> Integer Class --> intValue() Method Syntax: public int intValue() Return Type: A numeric value tha
3 min read
Integer rotateLeft() Method in Java
Bit shifting is a type of bitwise operation which is performed on all the bits of a binary value by moving the bits by a definite number of places towards left or right. Java has a single Logical left shift operator (<< ). When the value 0001(i.e., 1) is shifted left, it becomes 0010(i.e., 2) which on shifting again to the left becomes 0100 o
3 min read
Integer reverseBytes() Method in Java
The java.lang.Integer.reverseBytes(int a) is a built-in method which returns the value obtained by reversing the order of the bytes in the two's complement representation of the specified int value. Syntax : public static int reverseBytes(int a) Parameter: The method takes one parameter a of integer type whose bytes are to be reversed. Return Value
3 min read
Integer rotateRight() Method in Java
Bit shifting is used in programming and has at least one variation in each programming language. Java has a single Logical right shift operator (>>). Bit shifting is a type of bitwise operation. Bit shifting is done on all the bits of a binary value which moves the bits by a definite number of places to the right. If the value 0100; (ie. 4) i
2 min read
Integer sum() Method in Java
The java.lang.Integer.sum() is a built-in method in java that returns the sum of its arguments. The method adds two integers together as per the + operator. Syntax : public static int sum(int a, int b) Parameter: The method accepts two parameters that are to be added with each other: a : the first integer value. b : the second integer value. Return
2 min read
Integer shortValue() Method in Java
The Integer.shortValue() is an inbuilt method of java.lang which returns the value of this Integer in the short type . Syntax: public short shortValue() Parameters: The method does not take any parameters. Return Value: The method returns the integer value represented by this object after converting it to type short. Below programs illustrate the I
2 min read
Integer signum() Method in Java
The signum function is an odd mathematical function that extracts the sign of a real number. The signum function is also known as sign function. The Integer.signum() method of java.lang returns the signum function of the specified integer value. For a positive value, a negative value and zero the method returns 1, -1 and 0 respectively. Syntax : pu
3 min read
Integer floatValue() Method in Java
floatValue() method of Integer class present inside java.lang package is used to convert the value of the given Integer to a float type after a widening primitive conversion which in general is mostly applicable when we want to truncate or rounding-off the integer value. The package view is as follows: --> java.lang Package --> Integer Class
2 min read
Integer toOctalString() Method in Java
Octal is the base-8 number system and uses the digits 0 to 7 in operation. Octal is widely used in computing on systems like the PDP-8, and IBM mainframes employed 12-bit, 24-bit or 36-bit words. The Java.lang.Integer.toOctalString() method is a built-in function in Java that is used to return a string representation of the integer argument as an u
3 min read
Integer valueOf() Method in Java
1. The java.lang.Integer.valueOf(int a) is an inbuilt method which is used to return an Integer instance representing the specified int value a. Syntax : public static Integer valueOf(int a) Parameters : The method accepts a single parameter a of integer type representing the parameter whose Integer instance is to be returned. Return Value : The me
4 min read
Practice Tags :