ListIterator vs Iterator in Java
An Iterator can iterate in only one direction (forward direction), whereas ListIterator can iterate in both forward and back directions. We can add or set a value at any time in the lifespan of the ListIterator. ListIterator maintains two pointers viz. previous and next. An Iterator can be used to iterate over a list, set, or map structure. But a ListIterator is only used to iterate through a list. For example Set<Integer> mSet = new HashSet<Integer>(); mSet.add(0); mSet.add(1); Iterator<Integer> mSetIterator = mSet.iterator(); // we cannot do Iterator<Integer> mSetIterator = mSet.listIterator(); List<Integer> mList = new ArrayList<Integer>(); mList.add(0); mList.add(1); // following two statements are valid for listRead More →