Set Interface in Java


The Set interface is a collection that cannot contain duplicate elements, use it for unique collections.

Source Code

Set set = new HashSet();
set.add(1);
set.add(2);
set.add(1); // This will not be added
System.out.println(set.size()); // Outputs: 2
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments