mercredi 24 février 2016

Printing an array list with duplicate entries

Im storing names in a array list logcall and printing them out accordingly. But when there are duplicates how do I only print them once rather than however many times they're in the array list?

public static void displayHistory()
{
    for(Call allCalls : logCall) 
    {
        if(logCall!=null)
        {
            String name = allCalls.getName();
            Long phone = allCalls.getPhoneNumber();
            String type = allCalls.getType();
            String time = allCalls.getTime();
            String date = allCalls.getDate();

            String phoneStr = Long.toString(phone);

            if(name.equals("N/A"))
            {
                System.out.println( PhoneBook.formatNum(phoneStr) + " (" + type + ") " +date + " " + time);
            }
            else if(search(name) > 1)
            {
                System.out.println( name + " (" +search(name)+ ") " );
            }
            else
            {
                System.out.println( name + " (" + type + ") " + date + " " + time);
            }

        }
    }

Aucun commentaire:

Enregistrer un commentaire