Retrieve Items from a LinkedList in Java


Here is another Java snippet that can help to enhance your program by using LinkedLists. The code below will retrieve all items from a linkedList and print them one by one to the console.

class Main {
   public static void main(String[] args) {
  java.util.LinkedList<String> employees = new    java.util.LinkedList<String>();
    employees.add("Scott");
    employees.add("Marie");
    employees.add("Dun");

    for (String string : employees)
          System.out.println(string);
  }

}

Happy Coding!

More Java Snippets

Asha Shoukeir

About Asha shoukeir

Software Developer and System Administrator

View all posts by Asha shoukeir →

Leave a Reply