The
get(index) method of
CopyOnWriteArrayList returns the element at the specified index.
Syntax:
public E get(int index)
Parameters: The function accepts a mandatory parameter index which specifies the index of the element to be returned.
Return Value: The function returns the element at the given index.
Exceptions: The function throws
IndexOutOfBoundsException if the index is out of range.
Below programs illustrate the above function:
Program 1:
Output:
CopyOnWriteArrayList: [32, 67, 98, 100]
Element at 2nd index: 98
Program 2: