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("LinkedList contains : " + lList); lList.clear();/*from ww w . j a v a 2 s .c o m*/ System.out.println("LinkedList now contains : " + lList); }
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("H"); officers.add("P"); officers.add("M"); officers.add(2, "T"); for (String s : officers) System.out.println(s);// ww w. ja v a 2 s . co m }
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);/* w w w. j av a 2 s. c o m*/ lList.subList(2, 5).clear(); 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"); Object[] objArray = lList.toArray(); for (Object obj : objArray) { System.out.println(obj);/* w w w . j a v a2s .c o m*/ } }
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"); lList.add("2"); System.out.println(lList.indexOf("2")); System.out.println(lList.lastIndexOf("2")); }
From source file:Main.java
public static void main(String args[]) { LinkedList<String> ll = new LinkedList<String>(); ll.add("A"); ll.add("java2s.com"); ll.add("B");/*from w ww .j a v a 2 s . co m*/ 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"); if (lList.contains("4")) { System.out.println("LinkedList contains 4"); } else {// w ww . j a va 2 s. c o m System.out.println("LinkedList does not contain 4"); } }
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]); }// w w w .java 2s .c o m }
From source file:Main.java
public static void main(String[] argv) throws Exception { LinkedList queue = new LinkedList(); Object object = ""; queue.add(object); Object o = queue.removeFirst(); queue = (LinkedList) Collections.synchronizedList(queue); }
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 a2s . c o m System.out.println(lList.remove("2")); System.out.println(lList); Object obj = lList.remove(2); System.out.println(obj + " has been removed from LinkedList"); System.out.println(lList); }