Retrieving Items from a LinkedList with enhanced for loop - Java Language Basics

Java examples for Language Basics:for

Description

Retrieving Items from a LinkedList with enhanced for loop

Demo Code

import java.util.LinkedList;

public class Main {
  public static void main(String[] args) {
    LinkedList<String> officers = new LinkedList<String>();
    officers.add("Blake");
    officers.add("Bates");
    officers.add("Jack");
    officers.add("Tom");
    officers.add("Lady");
    officers.add(2, "new");
    for (String s : officers)
          System.out.println(s);//from w  ww. j  ava  2s .  c  o  m


  }

}

Related Tutorials