Advertisement
Guest User

Untitled

a guest
Sep 27th, 2013
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void testRemovalFromListTwo() {
  2.     List<SomeItem> list = new ArrayList<SomeItem>();
  3.          
  4.     list.add(new SomeItem("Penny", 1));
  5.     list.add(new SomeItem("Nickle", 5));
  6.     list.add(new SomeItem("Dime", 10));
  7.     list.add(new SomeItem("Quarter", 25));
  8.     list.add(new SomeItem("Dollar", 100));
  9.  
  10.     System.out.println("List contains: "+list);
  11.        
  12.     System.out.println("Removing anything with a value below 25 cents from list");
  13.     int size = list.size()-1;
  14.     for(int i=size;i>=0;i--) {
  15.         if (list.get(i).value < 25) {
  16.             list.remove(i);
  17.         }
  18.     }
  19.     System.out.println("List now contains: "+list);
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement