Java.lang.Integer.valueOf(int i) Method


Description

The java.lang.Integer.valueOf(int i) method returns a Integer instance representing the specified int value i.

Declaration

Following is the declaration for java.lang.Integer.valueOf() method

public static Integer valueOf(int i)

Parameters

i − This is an int value.

Return Value

This method returns a Integer instance representing i.

Exception

NA

Example

The following example shows the usage of java.lang.Integer.valueOf() method.

package com.tutorialspoint;

import java.lang.*;

public class IntegerDemo {

   public static void main(String[] args) {

      Integer i = new Integer(30);
   
      // returns a Integer instance representing the specified int value 
      System.out.println("Value = " + i.valueOf(2));
   }
} 

Let us compile and run the above program, this will produce the following result −

Value = 2
java_lang_integer.htm
Advertisements