java - Duplicates in arraylist not to be printed -


i have arraylist bankcustomers. customers occur more once (this happens if have more 1 account).

now want print customers, if occur more once want print them once.

heres non working code. prints whole list. how can add code print duplicates once?

public void showcustomers() {     private arraylist<customer> customers = new arraylist<customer>();               for(customer c: customers) {                                 system.out.println("first name: " + c.getfirstname());             system.out.println("last name: " + c.getlastname());             system.out.println("customer number: " + c.getnumber());              for(account : c.getaccounts()) {                 system.out.println("account number: " + a.getaccountid());             }                                                  } }    

i prefer not use hashset (if it's not neccesary). i'm trying learn arraylists now.

add elements set:

for (customer c: new hashset<customer>(customers)) {                     

from linked javadoc:

a collection contains no duplicate element


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -