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); // peek at the first element System.out.println("First element of the list:" + list.peekFirst()); }
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); // print element at index 3 System.out.println("Element at index 3 :" + list.get(3)); }
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); // print the last element of the list System.out.println("Last Element :" + list.getLast()); }
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); // peek at the last element System.out.println("Last element of the list:" + list.peekLast()); }
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); // peek at the head of the list System.out.println("Head of the list:" + list.peek()); }
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); // print the head of the list System.out.println("Head of list:" + list.element()); }
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); // print the first element of the list System.out.println("First Element :" + list.getFirst()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { LinkedList queue = new LinkedList(); Object object = ""; // Add to end of queue queue.add(object); // Get head of queue Object o = queue.removeFirst(); }
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"); list.add("java tutorial"); System.out.println(list);/*from w w w . j av a 2 s .c o m*/ // create an array and copy the list to it Object[] array = list.toArray(new Object[4]); System.out.println(Arrays.toString(array)); }
From source file:Employee.java
public static void main(String args[]) { LinkedList<Employee> phonelist = new LinkedList<Employee>(); phonelist.add(new Employee("A", "1")); phonelist.add(new Employee("B", "2")); phonelist.add(new Employee("C", "3")); Iterator<Employee> itr = phonelist.iterator(); Employee pe;//from www .j ava2 s. c o m while (itr.hasNext()) { pe = itr.next(); System.out.println(pe.name + ": " + pe.number); } ListIterator<Employee> litr = phonelist.listIterator(phonelist.size()); while (litr.hasPrevious()) { pe = litr.previous(); System.out.println(pe.name + ": " + pe.number); } }