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 linked list object LinkedList<Integer> list = new LinkedList<Integer>(); // populate the list list.add(-2); list.add(2);/*from w w w . ja va 2 s . co m*/ list.add(-12); list.add(8); // sort the list Collections.sort(list, Collections.reverseOrder()); System.out.println("List sorted in natural order: "); System.out.println(list); }
From source file:MainClass.java
public static void main(String args[]) { LinkedList<Integer> ll = new LinkedList<Integer>(); ll.add(-8); ll.add(20);/* w ww . jav a2 s .c om*/ ll.add(-20); ll.add(8); Comparator<Integer> r = Collections.reverseOrder(); Collections.sort(ll, r); System.out.print("List sorted in reverse: "); for (int i : ll) { System.out.print(i + " "); } System.out.println(); Collections.shuffle(ll); System.out.print("List shuffled: "); for (int i : ll) System.out.print(i + " "); System.out.println(); System.out.println("Minimum: " + Collections.min(ll)); System.out.println("Maximum: " + Collections.max(ll)); }
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("tutorial from java2s.com"); list.add("10"); // print the list System.out.println("LinkedList:" + list); // remove "10" System.out.println("10 is in the list:" + list.remove("10")); // 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 index for "Chocolate" System.out.println("Index for Chocolate:" + list.indexOf("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); // push Element the list list.push("Element"); // 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); // retrieve and remove the head of the list System.out.println("Head element of the list:" + list.poll()); // 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); // retrieve and remove the first element of the list System.out.println("First element of the list:" + list.pollFirst()); // 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 beggining of the list list.addFirst("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); // retrieve and remove the last element of the list System.out.println("Last element of the list:" + list.pollLast()); // 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); // check if the list contains "Coffee" System.out.println("List contains 'Coffee':" + list.contains("Coffee")); // check if the list contains "10" System.out.println("List contains '10':" + list.contains("10")); }