Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 14-11-2009
Member
 
Join Date: Jan 2009
Posts: 30
conversion of Object into integer in JAVA

Hi ,

I am java beginner. I was trying the conversion of Object into integer.
Below java code which I have used for this:

application.setAttribute("xyz",new Integer(5));

int total_Val=application.getAttribute("xyz");

//code to convert object into integer

When I trying to execute this code I get error.

Please help me to understand this conversion process if you can.
Reply With Quote
  #2  
Old 14-11-2009
Member
 
Join Date: Jan 2008
Posts: 1,515
Re: conversion of Object into integer in JAVA

Hello,

I don't have very much knowedge, but have tried this type of conversion.
I suggest you to try below code for the conversion object into integer:


application.setAttribute("xyz",new Integer(5));

int total_Val=(Integer)application.getAttribute("xyz");


If you execute this code you will get the object in the integer type.

I hope this clears your doubts.
Reply With Quote
  #3  
Old 14-11-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: conversion of Object into integer in JAVA

To convert object into integer, you should follow the below steps:

1. first you have to create the object
2. then convert object into string
3. and finally convert string into integer or float

Code:

int p =Integer.parseInt( object.toString() );
Reply With Quote
  #4  
Old 14-11-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: conversion of Object into integer in JAVA

Please use below inbuild methods of java to convert object into integer or long or float:

1. toInt(java.lang.String pqr)
// Converts the String object pqr to an int type.

2. toLong(java.lang.String pqr)
//Converts the String object pqr to a long type.

3. toFloat(java.lang.String pqr)
Converts the String object pqr to a float type.

Last edited by Katty : 14-11-2009 at 12:48 PM.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "conversion of Object into integer in JAVA"
Thread Thread Starter Forum Replies Last Post
Java BigDecimal to Integer Anthony12 Software Development 6 11-08-2010 05:09 PM
integer to string conversion cyber-noob Software Development 4 03-03-2010 10:26 PM
How to convert Double data type value into Integer one in Java Rover Software Development 4 25-09-2009 05:09 PM
String veriable to stream object conversion? Shashikant Software Development 2 02-02-2009 10:56 PM
Object test = new Object() <-- Java, best way in C++ ADISH Software Development 3 25-10-2008 02:32 PM


All times are GMT +5.5. The time now is 04:33 PM.