java linked list iterate code example
Example 1: iterate trough linked list java
#Enhances For Loop
for (String temp : linkedList) {
System.out.println(temp);
}
Example 2: java linked list iterator
import java.io.*;
import java.util.LinkedList;
import java.util.ListIterator;
public class LinkedListDemo {
public static void main(String args[])
{
LinkedList<String> list = new LinkedList<String>();
list.add("Geeks");
list.add("for");
list.add("Geeks");
list.add("10");
list.add("20");
System.out.println("LinkedList:" + list);
ListIterator list_Iter = list.listIterator(2);
System.out.println("The list is as follows:");
while(list_Iter.hasNext()){
System.out.println(list_Iter.next());
}
}
}