Advertisement
apl-mhd

ArrayListRemoveForLoopIterator

Jan 11th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Iterator;
  3.  
  4. public class ArrayListClass {
  5.  
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.  
  10.         ArrayList<Integer> arrayList = new ArrayList<>();
  11.         arrayList.add(1);
  12.         arrayList.add(2);
  13.         arrayList.add(3);
  14.         arrayList.add(4);
  15.         arrayList.add(5);
  16.  
  17.  
  18.         for(int i=0; i<5; i++){
  19.             arrayList.remove(i);
  20.         }
  21.  
  22.  
  23.         /*Iterator<Integer> it = arrayList.iterator();
  24.  
  25.         while (it.hasNext()){ //susing iterator no error
  26.  
  27.            Integer aa = it.next();
  28.  
  29.             System.out.println(aa);
  30.  
  31.             it.remove();
  32.  
  33.         }*/
  34.  
  35.         /*System.out.println(arrayList.size());
  36.  
  37.         for(int i=arrayList.size()-1; i>=0; i--){ //remove first to last no error
  38.             arrayList.remove(i);
  39.         }*/
  40.  
  41.         System.out.println(arrayList.size());
  42.  
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement