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...
posted 7 years ago
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>?