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

Despues:
1
2