I have a SortedSet<String> and would like to check a property for all of its subsets containing one string less than the set itself. Is there a standard way to do this ?
I don't like my idea below, which I haven't tried compiling yet. Since I am removing from the set while iterating, I have to use an Iterator rather than the simpler for-each loop.
I don't think that's going to work. Removing the item via the iterator is fine - but then you're adding it back again within the loop, and that's also going to be a problem.
One approach that should work would be to take a copy of the set values first - e.g. by using toArray(). Then you can iterate through the copy, and within that loop you're free to add and remove items from the original set.
Or you can just create a new TreeSet to be the subset. Iterate through the original set normally; if the originalset contains an element for which hasInterestingProperty() is true, add it to the subset.
You could create an array copy of the Set as Matthew suggested and then do your processing on that. Rather than removing an element from the array you could just ignore a specific element each time.
Joanne
The moth suit and wings road is much more exciting than taxes. Or this tiny ad:
a bit of art, as a gift, the permaculture playing cards