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.
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.
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() );
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.