Tuesday, May 26, 2015

Java Code to remove objects in a list iteration

// Handling removal of objects from a list using iterator,
// Removal of objects when amount is greater than balance in account

                        Iterator<Accounts> act_iterator = listAccounts.iterator();    
                        Collection<Accounts> accounts  =  null;
                        for (DueAmount dueAmt : listDueAmounts) {
                                while (act_iterator.hasNext()) {
                                   Accounts acctEnt = act_iterator.next();
                                     if (acctEnt.getAmount() < dueAmt.getAmount()) {
                                                    accounts.remove(acctEnt);
                                                }
                                 }
                        }

No comments:

Post a Comment