/** * Adds the specified element to this set if it is not already present. * More formally, adds the specified element <tt>e</tt> to this set if * the set contains no element <tt>e2</tt> such that <tt>e.equals(e2)</tt>. * If this set already contains the element, the call leaves the set * unchanged and returns <tt>false</tt>. * * @param e element to be added to this set * @return <tt>true</tt> if this set did not already contain the * specified element * @throws ClassCastException if <tt>e</tt> cannot be compared * with the elements currently in this set * @throws NullPointerException if the specified element is null */ public boolean add(Object e) { return m.putIfAbsent(e, Boolean.TRUE) == null; }
/** * Adds the specified element to this set if it is not already present. * More formally, adds the specified element <tt>e</tt> to this set if * the set contains no element <tt>e2</tt> such that <tt>e.equals(e2)</tt>. * If this set already contains the element, the call leaves the set * unchanged and returns <tt>false</tt>. * * @param e element to be added to this set * @return <tt>true</tt> if this set did not already contain the * specified element * @throws ClassCastException if <tt>e</tt> cannot be compared * with the elements currently in this set * @throws NullPointerException if the specified element is null */ public boolean add(Object e) { return m.putIfAbsent(e, Boolean.TRUE) == null; }
/** * Adds the specified element to this set if it is not already present. * More formally, adds the specified element <tt>e</tt> to this set if * the set contains no element <tt>e2</tt> such that <tt>e.equals(e2)</tt>. * If this set already contains the element, the call leaves the set * unchanged and returns <tt>false</tt>. * * @param e element to be added to this set * @return <tt>true</tt> if this set did not already contain the * specified element * @throws ClassCastException if <tt>e</tt> cannot be compared * with the elements currently in this set * @throws NullPointerException if the specified element is null */ public boolean add(Object e) { return m.putIfAbsent(e, Boolean.TRUE) == null; }