Iterate Through All Elements In LinkedList | Java Programs

Output:

*** Iterate Through All Elements Of LinkedList ***

Iterating Elements of LinkedList...

Java
HTML
CSS
JavaScript
PHP

Click Here For Java Online Compiler

Solution:

/**
 *
 * @author Alee Ahmed Kolachi
 */
import java.util.LinkedList;

public class IterateThroughElements {

    public static void main(String[] args) {

        LinkedList<String> linkedList = new LinkedList<>();

        linkedList.add("Java");
        linkedList.add("HTML");
        linkedList.add("CSS");
        linkedList.add("JavaScript");
        linkedList.add("PHP");
        System.out.println("*** Iterate Through All Elements Of LinkedList ***" + "\n");
        System.out.println("Iterating Elements of LinkedList..." + "\n");
        for (String element : linkedList) {
            System.out.println(element);
        }
    }
}
Share This :

Related Post



sentiment_satisfied Emoticon