The
addAllAbsent(E e) method of
CopyOnWriteArrayList appends all of the elements in the specified collection that are not already contained in this list, to the end of this list, in the order that they are returned by the specified collection's iterator.
Syntax:
public int addAllAbsent(Collection<E> collection)
Parameters: The function accepts a single mandatory parameter
collection which specifies the collection to be appended to the list if it is not present.
Return Value: The function returns
an integer value which is the number if elements added in the List.
Exception: This method throws
NullPointerException if the specified collection is null.
Below programs illustrate the addAllAbsent() function:
Program 1:
Output:
CopyOnWriteArrayList: [2, 3, 4, 7]
The collection to be appended: [1, 2, 3, 4]
Number of elements appended using addAllAbsent() method: 1
Modified CopyOnWriteArrayList: [2, 3, 4, 7, 1]
Program 2: To demonstrate NullPointerException