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>?
All of life is a contant education - Eleanor Roosevelt. Tiny ad: