Example usage for java.util LinkedList LinkedList

List of usage examples for java.util LinkedList LinkedList

Introduction

In this page you can find the example usage for java.util LinkedList LinkedList.

Prototype

public LinkedList() 

Source Link

Document

Constructs an empty list.

Usage

From source file:MainClass.java

public static void main(String[] a) {

    LinkedList list = new LinkedList();
    list.add("A");
    list.add("B");
    list.add("C");
    list.add("D");
    list.addFirst("X");
    list.addLast("Z");

    System.out.println(list);/* ww  w .j av  a2s.com*/
}

From source file:Main.java

public static void main(String[] args) {
    LinkedList<String> lList = new LinkedList<String>();
    lList.add("1");
    lList.add("2");
    lList.add("3");
    lList.add("4");
    lList.add("5");

    System.out.println("First element of LinkedList is : " + lList.getFirst());
    System.out.println("Last element of LinkedList is : " + lList.getLast());
}

From source file:MainClass.java

public static void main(String[] a) {

    LinkedList list = new LinkedList();

    list.add("A");
    list.add("B");
    list.add("C");
    list.add("D");
    list.addFirst("X");
    list.addLast("Z");

    System.out.println(list);//from   ww  w . j  a va 2s . co m
    System.out.println(list.getFirst());
    System.out.println(list.getLast());
}

From source file:Main.java

public static void main(String args[]) {

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

    ll.add("B");// www.j a va2s.  c  o m
    ll.add("ja v a2s.com");
    ll.addLast("E");
    ll.add("F");

    LinkedList<String> newList = new LinkedList<String>(ll);

    System.out.println(newList);
}

From source file:MainClass.java

public static void main(String[] a) {
    LinkedList<String> officers = new LinkedList<String>();
    officers.add("B");
    officers.add("B");
    officers.add("H");
    officers.add("P");
    officers.add("M");
    for (String s : officers)
        System.out.println(s);// w ww  .j  a v  a2s.co  m
}

From source file:Main.java

public static void main(String[] args) {
    LinkedList<String> lList = new LinkedList<String>();

    lList.add("1");
    lList.add("2");
    lList.add("3");
    lList.add("4");
    lList.add("5");

    System.out.println(lList);/*w ww  .  ja  v  a2  s.  c  om*/
    lList.set(3, "Replaced");
    System.out.println(lList);
}

From source file:Main.java

public static void main(String[] args) {
    LinkedList<String> lList = new LinkedList<String>();

    lList.add("1");
    lList.add("2");
    lList.add("3");
    lList.add("4");
    lList.add("5");

    for (String str : lList) {
        System.out.println(str);/*from  w  w  w . j a va2  s. co  m*/
    }
}

From source file:Main.java

public static void main(String[] args) {
    LinkedList<String> lList = new LinkedList<String>();

    lList.add("1");
    lList.add("2");
    lList.add("3");
    lList.add("4");
    lList.add("5");

    System.out.println("LinkedList contains : " + lList);
    lList.clear();//from   w  w  w.  j  av a 2  s  .  c o m
    System.out.println("LinkedList now contains : " + lList);
}

From source file:Main.java

public static void main(String[] args) {
    LinkedList<String> lList = new LinkedList<String>();

    lList.add("1");
    lList.add("2");
    lList.add("3");
    lList.add("4");
    lList.add("5");

    System.out.println(lList);/*ww w.  j  ava 2 s  . c  o  m*/
    lList.subList(2, 5).clear();
    System.out.println(lList);
}

From source file:MainClass.java

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);/*  w  w  w  .  j a v a 2s .  c  o m*/
}