Iterator

what is iterator in Java

Definition Interface that can read any class in the collection framework. Thus, we can read arraylist or linkedlist or hashmap with iterator. why we use iterator? Since we can read any list or set with iterator, we do not have to fix or change code when you work with big projects. Hierarchy method hasNext() next() remove() method Example List list = new ArrayList();// arrayList list.add("1"); list.add("2"); list.add("3"); Iterator <string> itr = list.