Guest User

Untitled

a guest
Aug 16th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. Java ArrayList concurrent modification
  2. for(Iterator<Object> i = mylist.iterator(); i.hasNext();) {
  3. Object obj = i.next();
  4. ArrayList<Object> newlist = new ArrayList<Object>();
  5. newlist.add(obj);
  6. i.remove();
  7. for(Iterator<Object> in = mylist.iterator(); in.hasNext();) {
  8. Object next = in.next();
  9. if (obj != next && (another condition)) {
  10. newlist.add(next);
  11. in.remove();
  12. }
  13. }
  14. if (newlist.size() > 2) anotheList.add(newlist);
  15. else for(Object r : newlist) {
  16. //mylist get back object:
  17. mylist.add(r);
  18. }
  19. }
  20.  
  21. while (!myList.isEmpty()) {
  22. Object obj = myList.remove(0);
  23. ...
  24. }
Add Comment
Please, Sign In to add comment