Posted By

theobriscoe on 12/03/08


Tagged

list remove clooection


Versions (?)

Remove from a list during iteration


 / Published in: Java
 

  1. // REMOVE: Any items that are not in the temporary list should be removed
  2. List<TravelProfilePopupDisplay> itemsToRemove = new ArrayList<TravelProfilePopupDisplay>();
  3. for (TravelProfilePopupDisplay originalProfileDisplay : originalList) {
  4.  
  5. boolean foundMatch = false;
  6. for (TravelProfilePopupDisplay tempProfileDisplay : tempTravelProfileDisplays ) {
  7. if (tempProfileDisplay.getID() == originalProfileDisplay.getID()) {
  8. foundMatch=true;
  9. }
  10. }
  11. // If the item only exists in the original list, then remove it
  12. if (foundMatch==false) {
  13. // Note: Cannot remove from originalList during iteration
  14. itemsToRemove.add( originalProfileDisplay );
  15. }
  16. }
  17. originalList.removeAll( itemsToRemove );

Report this snippet  

You need to login to post a comment.