List of usage examples for java.util LinkedList addFirst
public void addFirst(E e)
From source file:MainClass.java
public static void main(String[] a) { LinkedList<String> officers = new LinkedList<String>(); officers.addFirst("B"); officers.addFirst("B"); officers.addFirst("H"); officers.addFirst("P"); officers.addFirst("M"); for (String s : officers) System.out.println(s);//ww w .j a v a 2s .c o m }
From source file:MainClass.java
public static void main(String[] a) { LinkedList list = new LinkedList(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); list.addFirst("X"); list.addLast("Z"); System.out.println(list);/*w w w . ja va 2 s. c o m*/ }
From source file:MainClass.java
public static void main(String[] a) { LinkedList list = new LinkedList(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); list.addFirst("X"); list.addLast("Z"); System.out.println(list);//w ww.j av a 2 s. c om System.out.println(list.getFirst()); System.out.println(list.getLast()); }
From source file:MainClass.java
public static void main(String[] a) { LinkedList list = new LinkedList(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); list.addFirst("X"); list.addLast("Z"); System.out.println(list);/*from w w w . ja v a 2 s . c o m*/ System.out.println(list.getFirst()); System.out.println(list.getLast()); list.removeFirst(); list.removeLast(); System.out.println(list); }
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 ww w . j av a 2s. c om lList.addFirst("0"); System.out.println(lList); lList.addLast("6"); System.out.println(lList); }
From source file:MainClass.java
public static void main(String args[]) { LinkedList<String> ll = new LinkedList<String>(); ll.add("B");//from ww w . ja va2s . c o m ll.add("C"); 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); }
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 <T> List<T> inReverseOrder(Collection<T> src) { LinkedList<T> result = new LinkedList<T>(); for (T element : src) result.addFirst(element); return result; }
From source file:Main.java
public static <V> void splice(LinkedList<V> list, Iterator<V> iterator, LinkedList<V> list2, V v) { list2.remove(v);/*from w w w . java 2s .c om*/ assert (iterator.equals(list.iterator())); list.addFirst(v); }
From source file:Main.java
public static String toString(Iterable<Object> pathItrb) { LinkedList<Object> list = new LinkedList<Object>(); Iterator itr = pathItrb.iterator(); while (itr.hasNext()) { list.addFirst(itr.next()); }/* w w w .ja v a 2 s. co m*/ // StringBuilder sb = new StringBuilder(); boolean isFirst = true; for (Object obj : list) { if (isFirst) { isFirst = false; } else { sb.append("/"); // NOI18N } sb.append(obj.toString()); } // return sb.toString(); }