wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Converting String or Vector elements to 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 String or Vector elements to Int.." Watch "Converting String or Vector elements to Int.." New topic
Author

Converting String or Vector elements to Int..

Fredrik Komstadius
Greenhorn

Joined: Mar 29, 2002
Posts: 19
This might sound very stupid. Remember I'm a newbie Can I convert a string or Vector element which contains some numbers into and Int ?
If so how ?
/Bossakungen
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
bossakungen
Welcome to the Java Ranch, we hope you’ll enjoy visiting as a regular however,
your name is not in keeping with our naming policy here at the ranch. Please change your display name to an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!


Dave
Jason Kretzer
Ranch Hand

Joined: May 31, 2001
Posts: 280
If you are talking about the String "1234" with only numbers in it, then you can use Integer.parseInt(yourStringWithonlyNumbers).
This will return its int value.
HTH,


Jason R. Kretzer<br />Software Engineer<br />System Administrator<br /><a href="http://alia.iwarp.com" target="_blank" rel="nofollow">http://alia.iwarp.com</a>
Fredrik Komstadius
Greenhorn

Joined: Mar 29, 2002
Posts: 19
Thanx for the info! I really needed that!
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
Hi,
Can I convert a string or Vector element which contains some numbers into and Int ?

A Vector can't contain primitives so your numbers inside it has to be stored as a String or an Integer. Cast it back after retrieval. If it's a String parse it back as above (or it will throw a NumberFormatException in case of failure). If it's an Integer use intValue() to get your int.
-anthony
[ March 29, 2002: Message edited by: Anthony Villanueva ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Converting String or Vector elements to Int..