Example usage for java.util LinkedList add

List of usage examples for java.util LinkedList add

Introduction

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

Prototype

public boolean add(E e) 

Source Link

Document

Appends the specified element to the end of this 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);

    // 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[] args) {
    LinkedList<String> list = new LinkedList<String>();

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

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

    // print the size of the list
    System.out.println("List size:" + list.size());

    // add 2 more elements
    list.add("HTML");
    list.add("CSS");

    // print the size of the list
    System.out.println("List size:" + list.size());
}

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);

    // set Iterator as descending
    Iterator x = list.descendingIterator();

    // print list with descending order
    while (x.hasNext()) {
        System.out.println(x.next());
    }/* ww  w.  ja  v  a  2 s .c  o  m*/
}

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);

    // set Iterator at specified index
    Iterator x = list.listIterator(1);

    // print list with the iterator
    while (x.hasNext()) {
        System.out.println(x.next());
    }// ww  w  . j  av  a2  s  . com
}

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);
}

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 new collection and add some elements
    Collection collection = new ArrayList();
    collection.add("One");
    collection.add("Two");
    collection.add("Three");

    // append the collection in the LinkedList
    list.addAll(collection);//ww  w  .  ja v  a  2s  . c om

    // 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);

    // create a new collection and add some elements
    Collection collection = new ArrayList();
    collection.add("One");
    collection.add("Two");
    collection.add("Three");

    // add the collection in the LinkedList at index 2
    list.addAll(2, collection);//  ww w.  j  av  a  2s. c o m

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

From source file:LinkedListExample.java

public static void main(String[] args) {
    // Create a new LinkedList
    LinkedList<Integer> list = new LinkedList<Integer>();

    // Add Items to the array list
    list.add(new Integer(1));
    list.add(new Integer(2));
    list.add(new Integer(3));
    list.add(new Integer(4));
    list.add(new Integer(5));
    list.add(new Integer(6));
    list.add(new Integer(7));
    list.add(new Integer(8));
    list.add(new Integer(9));
    list.add(new Integer(10));

    // Use iterator to display the values
    for (Iterator i = list.iterator(); i.hasNext();) {
        Integer integer = (Integer) i.next();
        System.out.println(integer);
    }/*  w  ww.j a  va2s.co  m*/

    // Remove the element at index 5 (value=6)
    list.remove(5);

    // Set the value at index 5, this overwrites the value 7
    list.set(5, new Integer(66));

    // Use the linked list as a queue:
    // add an object to the end of the list (queue)
    // remove an item from the head of the list (queue)
    list.addLast(new Integer(11));
    Integer head = (Integer) list.removeFirst();
    System.out.println("Head: " + head);

    // Use iterator to display the values
    for (Iterator i = list.iterator(); i.hasNext();) {
        Integer integer = (Integer) i.next();
        System.out.println(integer);
    }
}

From source file:edu.csun.ecs.cs.multitouchj.application.chopsticks.Chopsticks.java

public static void main(String[] args) {
    LinkedList<String> arguments = new LinkedList<String>();
    for (String argument : args) {
        arguments.add(argument);
    }/*from  w ww.ja va 2 s  .co  m*/

    TreeMap<String, String> parameters = new TreeMap<String, String>();
    if (arguments.contains("-ix")) {
        parameters.put(ObjectObserverMoteJ.Parameter.InverseX.toString(), "");
    }
    if (arguments.contains("-iy")) {
        parameters.put(ObjectObserverMoteJ.Parameter.InverseY.toString(), "");
    }

    Chopsticks chopsticks = new Chopsticks();
    chopsticks.run(parameters);
}

From source file:edu.csun.ecs.cs.multitouchj.ui.test.PhotoTest.java

public static void main(String[] args) {
    LinkedList<String> arguments = new LinkedList<String>();
    for (String argument : args) {
        arguments.add(argument);
    }/*from  w ww .  j av a 2 s  .co  m*/

    TreeMap<String, String> parameters = new TreeMap<String, String>();
    if (arguments.contains("-ix")) {
        parameters.put(ObjectObserverMoteJ.Parameter.InverseX.toString(), "");
    }
    if (arguments.contains("-iy")) {
        parameters.put(ObjectObserverMoteJ.Parameter.InverseY.toString(), "");
    }

    PhotoTest photoTest = new PhotoTest();
    photoTest.run(parameters);
}