Win a copy of Securing DevOps this week in the Security forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Converting String or Vector elements to Int..  RSS feed

 
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
 
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!!
 
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!
 
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 ]
 
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!