List of usage examples for java.util LinkedList LinkedList
public LinkedList()
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);/* www . j a v a2s . c om*/ Object object = lList.removeFirst(); System.out.println(object + " has been removed"); System.out.println(lList); object = lList.removeLast(); System.out.println(object + " has been removed"); System.out.println(lList); }
From source file:AlgorithmsDemo.java
public static void main(String args[]) { LinkedList<Integer> ll = new LinkedList<Integer>(); ll.add(-8);//from w ww. ja v a2 s. co m ll.add(20); ll.add(-20); ll.add(8); Comparator<Integer> r = Collections.reverseOrder(); Collections.sort(ll, r); for (int i : ll) System.out.print(i + " "); Collections.shuffle(ll); System.out.print("List shuffled: "); for (int i : ll) System.out.print(i + " "); 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) { 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) { Queue<String> queue = new LinkedList<String>(); queue.offer("First"); queue.offer("Second"); queue.offer("Third"); queue.offer("Fourth"); queue.remove();/* w ww.ja v a 2s.co m*/ System.out.println(queue); }
From source file:Main.java
public static void main(String[] args) { List<String> list = new LinkedList<String>(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); String[] colors = new String[list.size()]; list.toArray(colors);/*from w w w .j av a 2 s .com*/ for (int i = 0; i < colors.length; i++) { System.out.println("color = " + colors[i]); } }
From source file:Main.java
public static void main(String args[]) { LinkedList<String> ll = new LinkedList<String>(); ll.add("A");//from w w w . j a va 2s . c o m ll.add("ja v a2s.com"); ll.addLast("B"); ll.add("C"); Iterator<String> itr = ll.iterator(); while (itr.hasNext()) { String element = itr.next(); System.out.print(element + " "); } }
From source file:Main.java
public static void main(String args[]) { LinkedList<String> ll = new LinkedList<String>(); ll.add("A");/*w w w . j a v a2 s. c om*/ ll.add("java2s.com"); ll.add("B"); ll.add("C"); ll.add("java2s.com"); Object[] objs = ll.toArray(); System.out.println(Arrays.toString(objs)); String[] strs = ll.toArray(new String[ll.size()]); System.out.println(Arrays.toString(strs)); }
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"); Iterator itr = lList.iterator(); while (itr.hasNext()) { System.out.println(itr.next()); }//from www . j a v a 2 s . c o m }
From source file:Main.java
public static void main(String[] args) { Queue<String> queue = new LinkedList<String>(); queue.offer("First"); queue.offer("Second"); queue.offer("Third"); queue.offer("Fourth"); System.out.println("Size: " + queue.size()); System.out.println("Queue head using peek : " + queue.peek()); System.out.println("Queue head using element: " + queue.element()); Object data;//from w w w . j av a 2s .c o m while ((data = queue.poll()) != null) { System.out.println(data); } }
From source file:Main.java
public static void main(String[] args) { LinkedList<String> theList = new LinkedList<String>(); theList.add("A"); theList.add("B"); theList.add("C"); theList.add("D"); String[] my = theList.toArray(new String[0]); for (int i = 0; i < my.length; i++) { System.out.println(my[i]); }//from w ww . j a v a 2s . c om }