Java examples for Collection Framework:LinkedList
Iterate through elements of LinkedList using Iterator
import java.util.Iterator; import java.util.LinkedList; public class Main { public static void main(String[] args) { //create LinkedList object LinkedList lList = new LinkedList(); /*from w w w . j av a2 s . c om*/ //add elements to LinkedList lList.add("1"); lList.add("2"); lList.add("3"); lList.add("4"); lList.add("5"); Iterator itr = lList.iterator(); System.out.println("Iterating through elements of Java LinkedList..."); System.out.println("LinkedList contains : "); while(itr.hasNext()) { System.out.println(itr.next()); } } }