Depends on what features you want in your collection. Basically the differences between Set<T>
and List<T>
are:
- A
List<T>
accepts duplicate elements, already Set<T>
not;
- A
List<T>
is mandatorily ordered while in Set<T>
this is optional and depends on the implementation. Example: elements of a HashSet<T>
are not sorted, whereas the elements of a TreeSet<T>
are ordered according to Comparator<T>
defined.
- A
List<T>
allows you to access elements through your position, Set<T>
does not allow this.
So, just see what features you need and choose the most appropriate collection. In your case, it probably does not make sense to have duplicate manufacturers in your collection, so a Set<T>
would be the best option.
It is also important to note that a Set<T>
checks for duplicate elements in the collection using the hashCode
and equals
methods. So, depending on what you consider as equal objects in your domain, you would need to override these methods so that Set<T>
identifies duplicates in a correct way.
Furthermore, by the way a Set<T>
works, the use of mutable elements is discouraged, since, from the moment an object is changed, the result of the hashCode
and equals
methods can also be changed. And in this scenario, the behavior of Set<T>
is not specified.