Question: I have an `ArrayList<SomeObject>` in java which contains some `<SomeObject>` multiple times.
I also have a `Set<SomeObject>`, which contains some elements one time only. The elements are only uniquely distinguishable only by their name (`String SomeObject.Name`).

How am I possible to see if the list has exactly the same elements as the set, but maybe multiple times?

Thanks

Answer: 
You could convert the ArrayList to a set by using HashSet:

```
HashSet listSet = new HashSet(arrayList);

```

To check whether the `ArrayList` initially has more elements, just compare the `listSet` and `arrayList` `size()` results:

```
boolean sameSize = listSet.size() == arrayList.size()

```

Then you can get the intersection of the two sets (the elements they have in common):

```
listSet.retainAll(set1)

```

If `listSet.size() == set1.size()` now, then they had the same elements, as all elements in the two lists were shared in common. To check whether the arrayList had repeating elements initially, check the value of the boolean from before: if `sameSize` is `true`, then they did, `false` means that they didn't.
All Java collections have method `boolean containsAll(collection<>)`, so if we want to check if two collections contain same elements, we can write `collection1.containsAll(collection2) && collection2.containsAll(collection1)` which will return `true` if `collection1` and `collection2` contain same elements.