Get Iterator from a List

Iterator<E> iterator()
Returns an iterator over the elements in this list in proper sequence.
ListIterator<E> listIterator()
Returns a list iterator over the elements in this list (in proper sequence).
ListIterator<E>listIterator(int index)
Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list.

import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class Main {
  public static void main(String[] args) {
    List list = Collections.nCopies(5, "java2s.com");
    System.out.println("List contains, ");
    Iterator itr = list.iterator();
    while (itr.hasNext()) {
      System.out.println(itr.next());

    }
  }
}

The output:


List contains, 
java2s.com
java2s.com
java2s.com
java2s.com
java2s.com
Home 
  Java Book 
    Collection  

List:
  1. List interface
  2. Add element to List
  3. Clear a List
  4. Does it contain certain element
  5. Compare two Lists
  6. Get the element index
  7. Get Iterator from a List
  8. Remove element from List
  9. Get/set element
  10. List size and empty flag
  11. Get the sub list from a list
  12. Convert List to Array