Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IteratorUtils.toList(iterator);
- List<String> list = new LinkedList<String>();
- while(iter.hasNext()) { // iter is of type Iterator<String>
- list.add(iter.next());
- }
- public T List<T> listFromIterator(Iterator<T> iterator) {
- List<T> result = new LinkedList<T>();
- while(iterator.hasNext()) {
- result.add(iterator.next());
- }
- }
- LinkedList(Collection<? extends E> c)
- ArrayList arrayList = new ArrayList();
- // add elements to the array list
- arrayList.add("C");
- arrayList.add("A");
- arrayList.add("E");
- arrayList.add("B");
- arrayList.add("D");
- arrayList.add("F");
- // use iterator to display contents of arrayList
- System.out.print("Original contents of arrayList: ");
- Iterator iterator = arrayList.iterator();
- ArrayList arrayList2 = new ArrayList();
- while(iterator.hasNext()) {
- Object element = iterator.next();
- arrayList2.add(element);
- System.out.print(element + " ");
- }
Add Comment
Please, Sign In to add comment