I tried searching around the site, but there is way too many threads with keywords interator or implementation. So, in a nut shell, what is the difference between various standard iterator implementations? I have not noticed anything different, besides the fact that .getClass() returns different strings.
List myList = (List) Arrays.asList("a", "b", "c", "d");
Set hashSet = new HashSet<String>();
Set treeSet = new TreeSet<String>();
ArrayList arrayList = new ArrayList<String>();
System.out.println(arrayList.iterator().getClass());//ArrayList
System.out.println(hashSet.iterator().getClass());//HashSet
System.out.println(myList.iterator().getClass());//List produced by Arrays.asList()
System.out.println(treeSet.iterator().getClass());//TreeSet
Result is as follows:
class java.util.ArrayList$Itr
class java.util.HashMap$KeyIterator
class java.util.AbstractList$Itr
class java.util.TreeMap$KeyIterator
So, why not keep the interface for people to implement in custom classes if needed, and have one concrete implementation across all Collections?
Collection, but they are part of what Oracle calls the collections framework.