- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
The get() method of CopyOnWriteArrayList in Java
The get() method of CopyOnWriteArrayList class returns the element at the specified position in this list.
The syntax is as follows:
E get(int index)
Here, the parameter index is the position from where you want the element.
To work with CopyOnWriteArrayList class, you need to import the following package:
import java.util.concurrent.CopyOnWriteArrayList;
The following is an example to implement CopyOnWriteArrayList class get() method in Java:
Example
import java.util.concurrent.CopyOnWriteArrayList; public class Demo { public static void main(String[] args) { CopyOnWriteArrayList<Integer> arrList = new CopyOnWriteArrayList<Integer>(); arrList.add(100); arrList.add(250); arrList.add(400); arrList.add(500); arrList.add(650); arrList.add(700); arrList.add(800); System.out.println("CopyOnWriteArrayList Elements = " + arrList); System.out.println("The element at 5th position = " + arrList.get(4)); System.out.println("The element at 7th position = " + arrList.get(6)); } }
Output
CopyOnWriteArrayList Elements = [100, 250, 400, 500, 650, 700, 800] The element at 5th position = 650 The element at 7th position = 800
Advertisements