- Type Parameters:
E- the element type of the set.
- All Known Subinterfaces:
AddToIntSet
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A function that adds an element to a set if not already present.
The set can be implemented in various ways. For example:
- The set can be an implementation of one of the collection classes
provided by the Java API.
AddToSet<E> = new HashSet<>()::add; - The set can be a marker bit on an element object.
class Element { private boolean marked; public boolean mark() { boolean wasMarked = false; marked = true; return wasMarked; } } AddToSet<Element> = Element::mark;
-
Method Summary
-
Method Details
-
add
Adds the specified element to the set if it is not already present.- Parameters:
e- element to be added to the set- Returns:
trueif this set did not already contain the specified element
-