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:Main.java

public static void main(String[] args) {

    // create a LinkedList
    LinkedList<String> list = new LinkedList<String>();

    // add some elements
    list.add("Hello");
    list.add("from java2s.com");
    list.add("10");

    // print the list
    System.out.println("LinkedList:" + list);

    // remove the head of the list
    list.remove();//from w  w  w.j  av a  2  s .  c  om

    // print the list
    System.out.println("LinkedList:" + list);
}

From source file:Main.java

public static void main(String[] args) {

    // create a LinkedList
    LinkedList<String> list = new LinkedList<String>();

    // add some elements
    list.add("Hello");
    list.add("Chocolate");
    list.add("10");

    // print the list
    System.out.println("LinkedList:" + list);

    // remove the element at index 2
    System.out.println("Element to be removed:" + list.remove(2));

    // print the list
    System.out.println("LinkedList:" + list);
}

From source file:Main.java

public static void main(String[] args) {

    // create a LinkedList
    LinkedList<String> list = new LinkedList<String>();

    // add some elements
    list.add("Hello");
    list.add("from");
    list.add("java2s.com");

    // print the list
    System.out.println("LinkedList:" + list);

    // remove the first element
    System.out.println("First element:" + list.removeFirst());

    // print the list
    System.out.println("LinkedList:" + list);
}

From source file:Main.java

public static void main(String[] args) {

    // create a LinkedList
    LinkedList<String> list = new LinkedList<String>();

    // add some elements
    list.add("Hello");
    list.add("from java2s.com");
    list.add("10");

    // print the list
    System.out.println("LinkedList:" + list);

    // add a new element at the end of the list
    list.addLast("Element");

    // print the new list
    System.out.println("LinkedList:" + list);
}

From source file:Main.java

public static void main(String[] args) {

    // create a LinkedList
    LinkedList<String> list = new LinkedList<String>();

    // add some elements
    list.add("Hello");
    list.add("from java2s.com");
    list.add("10");

    // print the list
    System.out.println("LinkedList:" + list);

    // offer a new element
    list.offer("Element");

    // print the new list
    System.out.println("LinkedList:" + list);
}

From source file:Main.java

public static void main(String[] a) {
    List<String> list = new LinkedList<String>();
    list.add("A");
    list.add("B");
    list.add("C");
    list.add("D");

    ListIterator iter = list.listIterator(1);
    while (iter.hasNext()) {
        System.out.println(iter.next());
    }// ww w .  j a v  a2  s  . c o  m

}

From source file:Main.java

public static void main(String[] a) {
    List<String> list = new LinkedList<String>();
    list.add("A");
    list.add("B");
    list.add("C");
    list.add("D");

    ListIterator iter = list.listIterator();
    while (iter.hasNext()) {
        System.out.println(iter.next());
    }/*  w ww  .  jav  a 2s. co m*/

}

From source file:MainClass.java

public static void main(String[] a) {
    List list = new LinkedList();
    list.add("A");
    list.add("B");
    list.add("C");
    list.add("D");

    ListIterator iter = list.listIterator(list.size());

    while (iter.hasPrevious()) {
        System.out.println(iter.previous());
    }/*  w w w .ja  v a 2  s.c o  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");

    ListIterator itr = lList.listIterator();
    System.out.println("forward direction");

    while (itr.hasNext()) {
        System.out.println(itr.next());
    }/*w  w w  . j a v  a 2 s.c  o  m*/
    System.out.println("reverse direction");
    while (itr.hasPrevious()) {
        System.out.println(itr.previous());
    }
}

From source file:Main.java

public static void main(String[] args) {

    // create a LinkedList
    LinkedList<String> list = new LinkedList<String>();

    // add some elements
    list.add("Hello");
    list.add("from java2s.com");
    list.add("10");

    // print the list
    System.out.println("LinkedList:" + list);

    // create a second LinkedList
    LinkedList list2 = new LinkedList();

    // clone list1
    list2 = (LinkedList) list.clone();

    // print list2
    System.out.println("LinkedList 2:" + list2);
}