Guest User

Untitled

a guest
Jun 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. package org.retard.collectionsTest;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashSet;
  5. import java.util.Iterator;
  6. import java.util.List;
  7. import java.util.Set;
  8.  
  9. public class ListIteratorStuff {
  10.  
  11. @SuppressWarnings("unchecked")
  12. public static void main(String[] args){
  13. // Start off with iterator
  14. Iterator iter = getIter();
  15. List convertMe = new ArrayList();
  16.  
  17. // Turn it into a list
  18. while (iter.hasNext()) {
  19. convertMe.add(iter.next());
  20. }
  21.  
  22. // Haz 10
  23. System.out.println(convertMe.size());
  24.  
  25. // Add another one
  26. convertMe.add("notherone-2");
  27.  
  28. // Haz 11
  29. System.out.println(convertMe.size());
  30.  
  31. // Strip dupes
  32. Set set = new HashSet(convertMe);
  33.  
  34. // Haz 10
  35. System.out.println(set.size());
  36.  
  37. Iterator bleh = set.iterator();
  38.  
  39. while(bleh.hasNext()){
  40. System.out.println(bleh.next());
  41. }
  42.  
  43. }
  44.  
  45. // Ignore this, I wanted to start with an Iterator
  46. public static Iterator getIter() {
  47. ArrayList<String> list = new ArrayList<String>();
  48.  
  49. for(int i = 0;i < 10; i++){
  50. list.add("notherone-" + i);
  51. }
  52.  
  53. return list.iterator();
  54. }
  55. }
Add Comment
Please, Sign In to add comment