The
add(E e) method of
CopyOnWriteArraySet inserts the element passed in the parameter to the end of the Set or at a specified index in the Set. The function returns true on addition of new element to the Set.
Syntax:
public boolean add(E e)
Parameters: The function accepts a single mandatory parameter
element which specifies the element to be added in the Set.
Return Value: The function returns
true on addition in the Set.
Below programs illustrate the above function:
Program 1:
Output:
CopyOnWriteArraySet: [2, 3, 4, 7]
On adding 4 it returns false
Updated CopyOnWriteArraySet: [2, 3, 4, 7]
Program 2: