Skip to Content

Convert java int to Integer object Example

  1. /*
  2.   Convert int to Integer object Example
  3.   This example shows how a int primitive value can be converted to Integer object
  4. */
  5.  
  6. public class IntToIntegerExample {
  7.  
  8.   public static void main(String[] args) {
  9.     int i = 10;
  10.    
  11.     /*
  12.     Use Integer constructor to convert int primitive type to Integer object.
  13.     */
  14.    
  15.     Integer intObj = new Integer(i);
  16.     System.out.println(intObj);
  17.    
  18.   }
  19. }
  20.  
  21. /*
  22. Output of the program would be
  23. 10
  24. */