Java Iterator.next()
Syntax
Iterator.next() has the following syntax.
E next()
Example
In the following code shows how to use Iterator.next() method.
/*w ww. ja va 2 s .c o m*/
import java.util.Iterator;
import java.util.LinkedList;
public class Main{
public static void main(String args[]) {
LinkedList<String> ll = new LinkedList<String>();
ll.add("A");
ll.add("ja v a2s.com");
ll.addLast("B");
ll.add("C");
Iterator<String> itr = ll.iterator();
while (itr.hasNext()) {
String element = itr.next();
System.out.print(element + " ");
}
}
}
The output:
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »