fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. List<MyObject> list = new ArrayList<>();
  13. list.add(new MyObject("abc"));
  14. list.add(new MyObject("def"));
  15. list.add(new MyObject("ghi"));
  16.  
  17. for(Iterator<MyObject> it = list.iterator(); it.hasNext();) {
  18. MyObject obj = it.next();
  19. if(obj.Id.compareTo("def") >= 0) {
  20. it.remove();
  21. }
  22. }
  23.  
  24. System.out.println(list.size());
  25. }
  26. }
  27.  
  28. class MyObject
  29. {
  30. public String Id;
  31.  
  32. public MyObject(String id) {
  33. Id = id;
  34. }
  35. }
Success #stdin #stdout 0.11s 320576KB
stdin
Standard input is empty
stdout
1