aspose file tools*
The moose likes Beginning Java and the fly likes converting a string to an int Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "converting a string to an int" Watch "converting a string to an int" New topic
Author

converting a string to an int

tyler jones
Ranch Hand

Joined: Dec 01, 2000
Posts: 101
I can't remember how to convert a string to an int. I have the variable x which has the value of "1". How can I then convert it to an int? I've tried something like...
int x = (int)x
and
int y = (int)x
but I always get errors. Thanks.
pjoisha
Ranch Hand

Joined: Mar 06, 2001
Posts: 123
How about
String x = "1";
int y = Integer.parseInt(x);
PJ

[This message has been edited by Prashanth Joisha (edited September 27, 2001).]
timothy zimmerman
Ranch Hand

Joined: Jun 26, 2001
Posts: 149
There are three methods that I could think of given
String x = "1"
new Integer(x).intValue()
Integer.valueOf(x).intValue()
and probably the preferred way as described in the previous post
Integer.parseInt(x)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: converting a string to an int