Make iterators cloneable?

Dave Brosius dbrosius at
Sat Sep 10 22:13:50 UTC 2016

It would be nice to be able to associate each element in a collection 
with another element in the collection, which is something very easily 
done with index based collections, but with sets, etc this isn't so 
easy... unless i'm having a brainfart.

So i'd like to do this, but Iterator doesn't implement Cloneable... Any 
reason not to? or is there another way that's missing me?

public class ItClone {

     public static void main(String[] args) {
         Set<String> s = Collections.newSetFromMap(new 
ConcurrentHashMap<String, Boolean>());


         Iterator<String> it1 = s.iterator();
         while (it1.hasNext()) {
             String v1 =;

             Iterator<String> it2 = (Iterator<String>) it1.*clone*();
             while (it2.hasNext()) {
                 String v2 =;

                 System.out.println(v1 + " <-->" + v2);

More information about the core-libs-dev mailing list