HashSet
is a Set which means it does not allow duplicates to be stored. That is the definition of Sets in java. So your list probably has duplicates which are removed when added to a HashSet
and hence the difference.
Below is the definition of a Set
as defined in the java docs. Please have a look at it for more information.
A collection that contains no duplicate elements. More formally, sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element. As implied by its name, this interface models the mathematical set abstraction.