VOOZH about

URL: https://www.geeksforgeeks.org/java/copyonwritearraylist-get-method-in-java/

⇱ CopyOnWriteArrayList get() method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

CopyOnWriteArrayList get() method in Java

Last Updated : 11 Jul, 2025
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:
Output:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
 at java.util.concurrent.CopyOnWriteArrayList.get(CopyOnWriteArrayList.java:388)
 at java.util.concurrent.CopyOnWriteArrayList.get(CopyOnWriteArrayList.java:397)
 at GFG.main(GFG.java:24)
Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CopyOnWriteArrayList.html#get-int-
Comment