If you know that primes contains only integers, you should make primes in TreeSet<Integer> .
Then it will be:
int start = 1 + primes.last().intValue();
If you cannot use generics, use this:
int start = 1 + ((Integer)prime.last()).intValue();
Casting in a string would be just plain stupid.
By the way, I do not suggest using autoboxing. He does everything behind your back. The explicit use of Integer seems clearer to me. But these are just my personal preferences, you can use autoboxing if you want.
Zifre
source share