Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String to Interger not working.

Status
Not open for further replies.

TheMillionDollarMan

Programmer
Jun 10, 2002
132
0
0
US

What is the best method for doing this?

I can't seem to compile I've tried:
int iStr;
String sStr = 10;
iStr.parseInt(sStr,10);

Error(146,14): object type required, but int found

and
getInteger(sPaymentFreq
and
new Integer(sPaymentFreq)

none seem to compile.
I have included
import java.lang.*;


Thanks
 
See what happens when you change this line:
String sStr = 10;
To:
String sStr = "10";
 
Well, I'm not sure where you got that code from, but it has several errors :

You cannot assign an int to a String object.
primitive data types like ints do not have methods - you need to use an object wrapper like Integer.

So try this :

String s = "10";
int i = Integer.parseInt(s);
 

Thanks Sedj. I used to have a library of all of these little tips so it was easier to look up.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top