When using list and set, we often use iterator to traverse the data ). With the downloader, you do not need to interfere with the traversal process. You only need to extract the desired data each time for processing.
However, they are different when used. Both list and set have iterator () to obtain its iterator. For list, you can also get its iterator through listiterator (). The two iterators cannot be used in some cases. The main differences between iterator and listiterator are as follows:
1. listiterator has the add () method, which can be used to add objects to the list. iterator cannot
2. both listiterator and iterator have hasnext () and next () methods, which can implement sequential backward traversal, but listiterator has hasprevious () and previous () methods, which can implement reverse (sequential forward) traverse. Iterator cannot.
3. listiterator can be used to locate the current index location. nextindex () and previousindex () can be used. Iterator does not have this function.
4. All objects can be deleted. However, listiterator can modify objects and set () can be implemented. Iierator can only be traversed and cannot be modified.
Because of these functions of listiterator, you can perform operations on the List data structure such as listing list. In fact, array objects can also be implemented using iterators.
Org. Apache. commons. Collections. iterators. arrayiterator can implement this function. Generally, we can use iterator. If you need to perform record search before and after repetition, you can use listiterator to expand your functions, (a little like the rolling result set in JDBC ).