List of usage examples for java.util LinkedList LinkedList
public LinkedList()
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);//w w w . j av a 2 s . c om } }
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 w w w . ja va 2 s . c om*/ 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); } }
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:CollectionAll.java
public static void main(String[] args) { List list1 = new LinkedList(); list1.add("list"); list1.add("dup"); list1.add("x"); list1.add("dup"); traverse(list1);/* w w w . ja va 2 s . com*/ List list2 = new ArrayList(); list2.add("list"); list2.add("dup"); list2.add("x"); list2.add("dup"); traverse(list2); Set set1 = new HashSet(); set1.add("set"); set1.add("dup"); set1.add("x"); set1.add("dup"); traverse(set1); SortedSet set2 = new TreeSet(); set2.add("set"); set2.add("dup"); set2.add("x"); set2.add("dup"); traverse(set2); LinkedHashSet set3 = new LinkedHashSet(); set3.add("set"); set3.add("dup"); set3.add("x"); set3.add("dup"); traverse(set3); Map m1 = new HashMap(); m1.put("map", "Java2s"); m1.put("dup", "Kava2s"); m1.put("x", "Mava2s"); m1.put("dup", "Lava2s"); traverse(m1.keySet()); traverse(m1.values()); SortedMap m2 = new TreeMap(); m2.put("map", "Java2s"); m2.put("dup", "Kava2s"); m2.put("x", "Mava2s"); m2.put("dup", "Lava2s"); traverse(m2.keySet()); traverse(m2.values()); LinkedHashMap /* from String to String */ m3 = new LinkedHashMap(); m3.put("map", "Java2s"); m3.put("dup", "Kava2s"); m3.put("x", "Mava2s"); m3.put("dup", "Lava2s"); traverse(m3.keySet()); traverse(m3.values()); }
From source file:ListDemo.java
public static void main(String args[]) { // do timing for LinkedList System.out.println("time for LinkedList = " + timeList(new LinkedList())); // do timing for ArrayList System.out.println("time for ArrayList = " + timeList(new ArrayList())); }
From source file:PrepareProduction.java
public static void main(String[] args) throws Exception { List q = Collections.synchronizedList(new LinkedList<String>()); Thread p1 = new Thread(new PrepareProduction(q)); Thread c1 = new Thread(new DoProduction(q)); p1.start();//from w w w . j a v a2s . c o m c1.start(); p1.join(); c1.join(); }
From source file:evaluation.evaluation2OrBACGeneration.java
public static void main(String[] args) throws IOException, ParseException, COrbacException { for (int i = 0; i < 5; i++) { String info = null;// w w w.j a v a 2 s . c om LinkedList<Long> policyGenerationTime = new LinkedList<Long>(); LinkedList<Long> allocationTime = new LinkedList<Long>(); for (int totalClientNumber = 10; totalClientNumber < 61; totalClientNumber = totalClientNumber + 10) { for (int totalHOSTNumber = 10; totalHOSTNumber < 61; totalHOSTNumber = totalHOSTNumber + 10) { int count = 0; util.test.VMAndHostGeneration(totalClientNumber, totalHOSTNumber); long returnValue[] = util.test.timeMeasure(totalClientNumber, totalHOSTNumber); info = info + "-----------------------------------\n"; info = info + "VM: " + totalClientNumber + "\n"; info = info + "HOST: " + totalHOSTNumber + "\n"; info = info + "Policy generation time: " + returnValue[0] + "\n"; info = info + "allocation time: " + returnValue[1] + "\n"; if ((totalClientNumber == 10) && (totalHOSTNumber == 10)) { policyGenerationTime.add(returnValue[0]); allocationTime.add(returnValue[1]); } else { policyGenerationTime.set(count, policyGenerationTime.get(count) + returnValue[0]); allocationTime.set(count, allocationTime.get(count) + returnValue[1]); } count++; } method.fromStringToFile(info, "evaluation" + File.separator + "test2and3.txt"); } } }
From source file:LinkedListTest.java
public static void main(String[] args) { List<String> a = new LinkedList<String>(); a.add("Amy"); a.add("Carl"); a.add("Erica"); List<String> b = new LinkedList<String>(); b.add("Bob"); b.add("Doug"); b.add("Frances"); b.add("Gloria"); // merge the words from b into a ListIterator<String> aIter = a.listIterator(); Iterator<String> bIter = b.iterator(); while (bIter.hasNext()) { if (aIter.hasNext()) aIter.next();// w w w . ja v a 2s . c o m aIter.add(bIter.next()); } System.out.println(a); // remove every second word from b bIter = b.iterator(); while (bIter.hasNext()) { bIter.next(); // skip one element if (bIter.hasNext()) { bIter.next(); // skip next element bIter.remove(); // remove that element } } System.out.println(b); // bulk operation: remove all words in b from a a.removeAll(b); System.out.println(a); }
From source file:com.google.flightmap.parsing.faa.nasr.tools.RecordClassMaker.java
public static void main(String[] args) { try {//ww w . j a v a2s . c om final BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); final String name = in.readLine(); final List<RecordEntry> entries = new LinkedList<RecordEntry>(); String line; while ((line = in.readLine()) != null) { final String[] parts = line.split("\\s+"); final int length = Integer.parseInt(parts[0]); final int start = Integer.parseInt(parts[1]); final String entryName = parts[2]; entries.add(new RecordEntry(length, start, entryName)); } (new RecordClassMaker(name, entries)).execute(); } catch (Exception ex) { ex.printStackTrace(); System.exit(1); } }
From source file:me.smoe.adar.pool.commonpool.CommonPool.java
public static void main(String[] args) throws NoSuchElementException, IllegalStateException, Exception { GenericObjectPool<Book> objectPool = new GenericObjectPool<Book>(new BookPoolFactory(), buildPoolConfig(5, 10, 2));//from ww w .j ava 2 s . com prestartCorePool(objectPool); List<Book> books = new LinkedList<Book>(); for (int i = 0; i < 10; i++) { books.add(objectPool.borrowObject()); } for (Book book : books) { objectPool.returnObject(book); } }