Add value to the first position in a linked list

 
import java.util.LinkedList;

public class Main {
  public static void main(String[] a) {

    LinkedList<String> officers = new LinkedList<String>();
    officers.addFirst("B");
    officers.addFirst("B");
    officers.addFirst("H");
    officers.addFirst("P");
    officers.addFirst("M");
    for (String s : officers)
      System.out.println(s);
  }
}
  
Home 
  Java Book 
    Runnable examples  

Collection LinkedList:
  1. Add value to the first position in a linked list
  2. Convert a LinkedList to ArrayList
  3. Remove first and last elements of LinkedList Java example