wiley_pastebin

lesson 4 exceptions 3

Mar 15th, 2019
2,201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.33 KB | None | 0 0
  1. public class Database {
  2.  private ArrayList<Item> items;
  3.  //...
  4.  
  5.  public void removeItem(String title) throws Exception{
  6.    for(int i = 0; i < items.size(); i++){
  7.     if(items.get(i).getTitle().equals(title)){
  8.     items.remove(i);
  9.     return;
  10.    }
  11.   }
  12.  throw new Exception("Item not found");
  13.  }
  14.  
  15.  //...
  16. }
Advertisement
Add Comment
Please, Sign In to add comment