Guest User

Untitled

a guest
Oct 16th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. IteratorUtils.toList(iterator);
  2.  
  3. List<String> list = new LinkedList<String>();
  4.  
  5. while(iter.hasNext()) { // iter is of type Iterator<String>
  6. list.add(iter.next());
  7. }
  8.  
  9. public T List<T> listFromIterator(Iterator<T> iterator) {
  10.  
  11. List<T> result = new LinkedList<T>();
  12. while(iterator.hasNext()) {
  13. result.add(iterator.next());
  14. }
  15.  
  16. }
  17.  
  18. LinkedList(Collection<? extends E> c)
  19.  
  20. ArrayList arrayList = new ArrayList();
  21. // add elements to the array list
  22. arrayList.add("C");
  23. arrayList.add("A");
  24. arrayList.add("E");
  25. arrayList.add("B");
  26. arrayList.add("D");
  27. arrayList.add("F");
  28.  
  29. // use iterator to display contents of arrayList
  30. System.out.print("Original contents of arrayList: ");
  31. Iterator iterator = arrayList.iterator();
  32. ArrayList arrayList2 = new ArrayList();
  33.  
  34. while(iterator.hasNext()) {
  35.  
  36. Object element = iterator.next();
  37. arrayList2.add(element);
  38. System.out.print(element + " ");
  39.  
  40. }
Add Comment
Please, Sign In to add comment