This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Number format exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Number format exception " Watch "Number format exception " New topic

Number format exception

vignesh Thamarai
Ranch Hand

Joined: Mar 10, 2009
Posts: 31
hello friends,
i have a hashset contain integers like 1,2,4,5 . now i want to get every integer value from hashset.

here is my code. set2 is a hashset.

it throws a number format exception , i try this one this too not helping me

please help me what iam missing...
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38033
What have you put into the Set in the first place? If there are Integers in it, there is no need to mess around with the parseInt and toString methods; you simply get the Integer out and can convert it to an int with auto-unboxing if necessary.

Your code is poorly formatted, which makes it difficult to read; there should, for example, be a single space after the semicolons in the for () line. Put the line starting int i = inside a try block, then follow it with a catch, so ti reads like thisThat will allow you to see what you have in your Set that isn't a number.

And why don't you parameterise the set as a Set<Integer>?
I agree. Here's the link:
subject: Number format exception
Similar Threads
problems with hashset
Comparing two collections...
Left join question in hibernate
Doubt in List
Formatting JTextArea