Assuming it Set s1contains the same content in the first and second examples, the final results should match.
(However, the second example will not compile because it Setis an interface, not a specific class.)
One of the advantages of using a constructor HashSet(Collection)is that it will have an initial capacity sufficient for storage Collection(in this case Set s1), which is passed to the constructor:
, . HashMap (0,75) .
, HashSet(), 16, , Set, Collection.addAll 16, :
; backing HashMap (16) (0,75).
, HashSet(Collection) HashSet, , .
, , union, -, , Set Set, , , , addAll, .
, Set , , , Set -, newSet, copyOfS1 - .