List of usage examples for java.util LinkedList add
public boolean add(E e)
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.add(2, "Element"); // print the updated 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.add("Element"); // print the updated 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); // pop the list System.out.println("Pop element in the list:" + list.pop()); // 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); // get the last index for "Hello" System.out.println("Index for Hello:" + list.lastIndexOf("Hello")); // get the index for "Coffee" System.out.println("Index for Coffee:" + list.indexOf("Coffee")); }
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); // clear the list list.clear();//from w w w . ja v a2 s.c o m // 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); // remove the head of the list list.remove();//from w w w.j a v a 2 s .c o m // 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:MainClass.java
public static void main(String args[]) { LinkedList<String> ll = new LinkedList<String>(); ll.add("B"); ll.add("C");//from ww w . ja v a 2s. c o m ll.add("D"); ll.add("E"); ll.add("F"); ll.addLast("Z"); ll.addFirst("A"); ll.add(1, "A2"); System.out.println("Original contents of ll: " + ll); ll.remove("F"); ll.remove(2); System.out.println("Contents of ll after deletion: " + ll); ll.removeFirst(); ll.removeLast(); System.out.println("ll after deleting first and last: " + ll); String val = ll.get(2); ll.set(2, val + " Changed"); System.out.println("ll after change: " + ll); }