I was going through the add
method of HashSet
. It is mentioned that
If this set already contains the element, the call leaves t
public boolean add(E e) {
return map.put(e, PRESENT)==null;
}
e is the key, So if e is already present put
will not return null
. Hence add
will return false.
JavaDoc for put
:
the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key.)