jam/ArrayListRemove

From ggc

Jump to: navigation, search

01 package jam;
02 
03 import wiki.Wiki;
04 import java.util.*;
05 /**
06  * All about my application here.
07  @author Jam Jenkins
08  */
09 public class ArrayListRemove
10 {
11    public static void main(String[] args)
12    {
13       ArrayList<Integer> all=new ArrayList<Integer>();
14       Random random=new Random();
15       for(int i=0; i<100; i++)
16       {
17          all.add(random.nextInt(10));
18       }
19       ArrayList<Integer> toRemove=new ArrayList<Integer>();
20       for(int x: all)
21       {
22          if(x==4)
23          {
24             toRemove.add(x);
25             //cannot do this:
26             //all.remove(x);
27          }
28       }
29       all.removeAll(toRemove);
30       for(int x: all)
31          Wiki.out.println("Number is "+x);
32    }
33 }


Download/View jam/ArrayListRemove.java




Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter