fork(3) 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. ArrayList<Integer> numbers = new ArrayList<>();
  13. numbers.add(10);
  14. numbers.add(20);
  15. numbers.add(30);
  16. numbers.add(40);
  17. System.out.println("add(값)");
  18. System.out.println(numbers);
  19.  
  20. numbers.add(1, 50);
  21. System.out.println("\nadd(인덱스, 값)");
  22. System.out.println(numbers);
  23.  
  24. numbers.remove(2);
  25. System.out.println("\nremove(인덱스)");
  26. System.out.println(numbers);
  27.  
  28. System.out.println("\nget(인덱스)");
  29. System.out.println(numbers.get(2));
  30.  
  31. Iterator<Integer> it = numbers.iterator();
  32. System.out.println("\niterator");
  33. while(it.hasNext()){
  34. int value = it.next();
  35. if(value == 30){
  36. it.remove();
  37. }
  38. }
  39. System.out.println(numbers);
  40.  
  41. System.out.println("\nfor each");
  42. for(int value : numbers){
  43. System.out.println(value);
  44. }
  45. }
  46. }
Success #stdin #stdout 0.07s 381248KB
stdin
Standard input is empty
stdout
add(값)
[10, 20, 30, 40]

add(인덱스, 값)
[10, 50, 20, 30, 40]

remove(인덱스)
[10, 50, 30, 40]

get(인덱스)
30

iterator
[10, 50, 40]

for each
10
50
40