Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
A Set represents a mathematical set. It is a Collection that, unlike List, does not allow duplicates. There must not be two elements of a Set, say e1 and e2, such that e1.equals(e2). The add method of Set returns false if you try to add a duplicate element. For example, this code prints "addition failed."
Set set = new HashSet();
set.add("Hello");
if (set.add("Hello")) {
System.out.println("addition successful");
} else {
System.out.println("addition failed");
}