EDIT:. This answer was designed for a single-threaded case, since I interpreted the OP question as avoiding codification, and not avoiding problems from multithreading. I leave this answer here if it proves useful for anyone in the future who uses a single-threaded approach.
There is no direct way to accomplish this. However, one option that is pretty good is to have two sets - the main set that you iterate over and the secondary set into which you insert all the new elements that you need to add. You can then iterate over the main set, and then after that go and use addAll to add all the new elements to the main set.
For example:
Set<T> masterSet = Set<T> newElems = for (T obj: masterSet) { } masterSet.addAll(newElems);
Hope this helps!
templatetypedef
source share