Java Integer.valueOf(int i) example

Java Integer.valueOf(int i) example

By Yashwant Chavan, Views 4, Date 14-Apr-2018

In this java tutorial, You will learn how to use valueOf(int i) method of Integer class. This method, Returns 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.

tags Java

Returns an Integer instance representing the specified int value.


public static Integer valueOf(int i)


i - an int value.


An Integer instance representing i.

Java Integer valueOf(int i) example

  • Assign two integer values.
  • Integer.valueOf(firstValue);It will return the integer value of firstValue.
  • Integer.valueOf(secondValue);It will return the integer value of secondValue.
  • Print the values.
package com.technicalkeeda;

public class App {

    public static void main(String[] args) {
  Integer firstValue = 45;
        Integer secondValue = 80;

        Integer result1 = Integer.valueOf(firstValue);
        Integer result2 = Integer.valueOf(secondValue);

        System.out.println("The integer value of firstValue :- " + result1);
        System.out.println("The integer value of secondValue :- " + result2);


The integer value of firstValue :- 45
The integer value of secondValue :- 80


Hi there! I am founder of and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan[at][]