Facebook Page Twitter Page LinkedIn Page
× Java.lang Package Classes

The java.lang.Integer.valueOf() method is used to return an Integer instance representing the specified int value. If a new Integer instance is not required, this method should generally be used in preference to the constructor Integer(int), as this method is likely to yield significantly better space and time performance by caching frequently requested values. This method will always cache values in the range -128 to 127, inclusive, and may cache other values outside of this range.


public static Integer valueOf(int i)


i Specify an int value.

Return Value

Returns a Integer instance representing i.




In the below example, the java.lang.Integer.valueOf() method is used to return a Integer instance representing the given int value.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    //creating int value
    int x = 25;

    //creating Integer instance
    Integer y = Integer.valueOf(x);

    //printing the int value 
    System.out.println("The int value is: " + x); 

    //printing the Integer instance 
    System.out.println("The Integer instance is: " + y);   

The output of the above code will be:

The int value is: 25
The Integer instance is: 25

❮ Java.lang - Integer