Convert Object to Int

In this section, we are going to learn to convert a numeric string type Object into a primitive type int and Integer Object to primitive type int.

Convert Object to Int

In this section, we are going to learn to convert a numeric string type Object into a primitive type int and Integer Object to primitive type int.

Convert Object to Int

Convert Object to Int

     

In this section, we are going to learn to convert a numeric string type Object into a primitive type int and Integer Object to primitive type int. . 

Code Description:

The following program converts numeric string type object into primitive type int and Integer type object to primitive type int. The parseInt() method of an Integer class takes a numeric string object and returns the primitive type int value. Again, this program converts an Integer object into  a primitive type int using the intValue() method.

Here is the code of this program:

import java.io.*;
import java.lang.*;

public class ObjectToInt{
  public static void main(String[] args){
  //Numeric string to primitive int
  String Obj = "123";
  int i = Integer.parseInt(Obj);
  System.out.println("Numeric string to primitive int = " +i);
  //Integer object to primitive int
  Integer IntValue = 123;
  int intValue = IntValue.intValue();
  System.out.println("Integer object ot primitive int = "+intValue);
  }
}

Download this program:

Output of this program

C:\vinod>javac ObjectToInt.java

C:\vinod>java ObjectToInt
Numeric string to primitive int = 123
Integer object ot primitive int = 123

C:\vinod>