Home Java Java-conversion Convert Object to Int



Convert Object to Int
Posted on: July 4, 2007 at 12:00 AM
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. . 

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>

Related Tags for Convert Object to Int:
cstringclassobjectconvertparseintegermethodtypevaluereturnintprimitivenumericprogramtorameitmitpeiminasmntpartrjclesmeintoobjprosurnkllivparseintfollowandarstrrtrtswingvassriringthstalujeprmindonogrolo


More Tutorials from this section

Ask Questions?    Discuss: Convert Object to Int   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.