Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Converting String or Vector elements to Int..

 
Fredrik Komstadius
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
Jason Kretzer
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Fredrik Komstadius
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx for the info! I really needed that!
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic