LinkedList Iterator iterator() method Example Program
By candid | Posted :
Jun 30, 2015
| Updated :
Jun 30, 2015
Returns an iterator over the elements in this deque in proper sequence. The elements will be returned in order from first (head) to last (tail).
Program
package com.candidjava;
import java.util.Iterator;
import java.util.LinkedList;
/**
*
* @author : mohan
* @description :Returns an iterator over the elements in this deque in proper
* sequence. The elements will be returned in order from first
* (head) to last (tail).
*/
public class LinkedListIterator {
public static void main(String[] args) {
LinkedList list = new LinkedList();
list.add("anandh");
list.add("hari");
list.add("vinoth");
list.add("mohan");
list.add("hari");
System.out.println("LinkedList:" + list);
Iterator x = list.listIterator(1);
while (x.hasNext()) {
System.out.println(x.next());
}
}
}
Output
LinkedList:[karthi, mohan, anand, hari, kamal]
karthi
mohan
anand
hari
kamal
Explanation
Iterator<E> iterator()
Returns an iterator over the elements in this deque in proper sequence. The elements will be returned in order from first (head) to last (tail).
Specified by:
iterator in interface Collection<E>
Specified by:
iterator in interface Iterable<E>
Returns:
an iterator over the elements in this deque in proper sequence