I am trying to make a list that contains four variable (integer, double, double, string). I need to create two methods. One method to add another entry to the list (but only if the integer variable is unique in the list), and another method that removes a specified entry (again, based on integer variable) from the list. I am having a lot of trouble setting up the ArrayList so that I can iterate through it in order to implement these two methods (I've tried a bunch of approaches, but nothing seems to be doing the trick). I appreciate any help with what I'm doing wrong!
ArrayList collection=new ArrayList(); //initialization of trade collection public void addTrade(int identifier, double amount, double rate, String currency){ //addTrade: inserts a single FXTrade instance into the collection for (int i = 0; i < collection.size(); i++){ //ensure the instance is unique before adding to the list Object currElement = collection.get(i); if (currElement == collection(identifier, amount, rate, currency)){ //don't add the new trade instance if it's already in the collection continue; }else { collection.add(identifier, amount, rate, currency); } } } public void removeTrade(int identifier){ //removeTrade: removes a single FXTrade instance from the collection //search collection for requested trade; remove the requested trade (if it's in the collection) for (int i = 0; i < collection.size(); i++){ if (collection.get(i)==identifier){ collection.remove(i); break; //once the trade is removed, stop iteration (uniqueness was checked in addTrade method) } } }