List of usage examples for java.util LinkedList LinkedList
public LinkedList()
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) { List<Integer> list = new LinkedList<Integer>(); list.add(1);/*from www .j av a 2 s . c om*/ List<Integer> unmodifiableList = Collections.unmodifiableList(list); System.out.println(unmodifiableList.getClass()); if (unmodifiableList.getClass().getName().contains("UnmodifiableList")) System.out.println(true); }
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[] a) { List list = new LinkedList(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); ListIterator iter = list.listIterator(); while (iter.hasNext()) { System.out.println(iter.next()); }/* w ww . jav a 2 s . com*/ }
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); }