Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.retard.collectionsTest;
- import java.util.ArrayList;
- import java.util.HashSet;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Set;
- public class ListIteratorStuff {
- @SuppressWarnings("unchecked")
- public static void main(String[] args){
- // Start off with iterator
- Iterator iter = getIter();
- List convertMe = new ArrayList();
- // Turn it into a list
- while (iter.hasNext()) {
- convertMe.add(iter.next());
- }
- // Haz 10
- System.out.println(convertMe.size());
- // Add another one
- convertMe.add("notherone-2");
- // Haz 11
- System.out.println(convertMe.size());
- // Strip dupes
- Set set = new HashSet(convertMe);
- // Haz 10
- System.out.println(set.size());
- Iterator bleh = set.iterator();
- while(bleh.hasNext()){
- System.out.println(bleh.next());
- }
- }
- // Ignore this, I wanted to start with an Iterator
- public static Iterator getIter() {
- ArrayList<String> list = new ArrayList<String>();
- for(int i = 0;i < 10; i++){
- list.add("notherone-" + i);
- }
- return list.iterator();
- }
- }
Add Comment
Please, Sign In to add comment