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) { 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);//from w w w . j a v a 2 s. c o m lList.addFirst("0"); System.out.println(lList); lList.addLast("6"); System.out.println(lList); }
From source file:Main.java
public static void main(String[] args) { LinkedList<String> myQueue = new LinkedList<String>(); myQueue.add("A"); myQueue.add("B"); myQueue.add("C"); myQueue.add("D"); List<String> myList = new ArrayList<String>(myQueue); for (Object theFruit : myList) System.out.println(theFruit); }
From source file:Main.java
public static void main(String[] args) { LinkedList<String> list = new LinkedList<String>(); list.add("Hello"); list.add("from java2s.com"); list.add("java tutorial"); // print the list System.out.println("LinkedList:" + list); // create an array and copy the list to it Object[] array = list.toArray(); System.out.println(Arrays.toString(array)); }
From source file:MainClass.java
public static void main(String[] a) { LinkedList<String> officers = new LinkedList<String>(); officers.add("B"); officers.add("B"); officers.add("T"); officers.add("H"); officers.add("P"); officers.add("McIntyre"); System.out.println(officers); officers.set(2, "Murdock"); System.out.println("\nTuttle is replaced:"); System.out.println(officers); }
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);// ww w. j a v a 2 s . co m List lst = lList.subList(1, 4); System.out.println(lst); lst.remove(2); System.out.println(lst); System.out.println(lList); }
From source file:ReverseIterating.java
public static void main(String... args) { LinkedList<String> list = new LinkedList<String>(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); list.add("E"); for (String s : new ReverseIterating<String>(list)) { System.out.println(s);//from ww w . j av a 2s .c om } }
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);/* ww w . ja va 2 s. com*/ 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: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()); }/*from ww w.j a v a 2 s .co m*/ System.out.println("reverse direction"); while (itr.hasPrevious()) { System.out.println(itr.previous()); } }
From source file:Address.java
public static void main(String args[]) { LinkedList<Address> ml = new LinkedList<Address>(); ml.add(new Address("A", "11 Ave", "U", "IL", "11111")); ml.add(new Address("R", "11 Lane", "M", "IL", "22222")); ml.add(new Address("T", "8 St", "C", "IL", "33333")); for (Address element : ml) System.out.println(element + "\n"); }
From source file:AlgorithmsDemo.java
public static void main(String args[]) { LinkedList<Integer> ll = new LinkedList<Integer>(); ll.add(-8); ll.add(20);// w w w . ja v a2s. c om 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)); }