Java HashSet(Collection <? extends E > c) Constructor
Syntax
HashSet(Collection <? extends E > c) constructor from HashSet has the following syntax.
public HashSet(Collection <? extends E> c)
Example
In the following code shows how to use HashSet.HashSet(Collection <? extends E > c) constructor.
/*ww w .j a v a 2s . c om*/
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
public class Main {
public static void main(String args[]) {
List<String> list = new ArrayList<>();
list.add("java2s.com");
list.add("java2s.com");
list.add("java2s.com");
HashSet<String> hs = new HashSet<String>(list);
System.out.println(hs);
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »