Question: I have a object in java called foo.
I can do `foo.getDate();` and that will give me the date of one item.
But now I have a `list<foo>` and I want to get per item one date.
So if I loop through my list I will see this output:

```
3-1-2015
3-1-2015
5-1-2015
8-1-2015
8-1-2015

```

But I want to see:

```
3-1-2015
5-1-2015
8-1-2015

```

So I want that only the first item with a unique date will be added to the list.
How can I do this in Java? 

Thanks in advance!

Answer: 
Create Set which will store unique Dates. If date from your foo instance was not already added to set add this instance to list containing foo objects with unique dates.

```
List<Foo> list = new ArrayList<>();
//fill list with your foo instances

Set<Date> uniqueDates = new HashSet<>();
List<Foo> resultList = new ArrayList<>();

for (Foo f : list){
    if (uniqueDates.add(f.getDate())){//if I was able to add date to set
        //it means that instance with this date is seen first time
        //so I can add it to result list
        resultList.add(f);
    }
}

```
well you probably should use `Set` for this.