- Trending Categories
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 lastIndexOf() method of CopyOnWriteArrayList in Java
The lastIndexOf() method returns the index of the last occurrence of the specified element in this list. It returns -1 if this list does not contain the element.
The syntax is as follows
public int lastIndexOf(Object ob)
Here, ob is the element. The return value would be the last index of this 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 lastIndexOf() 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(50); arrList.add(90); arrList.add(500); arrList.add(200); arrList.add(350); arrList.add(500); arrList.add(650); System.out.println("CopyOnWriteArrayList = " + arrList); System.out.println("The last index of element 500 = "+arrList.lastIndexOf(500)); } }
Output
CopyOnWriteArrayList = [50, 90, 500, 200, 350, 500, 650] The last index of element 500 = 5
- Related Articles
- How to use lastIndexOf() in android CopyOnWriteArrayList?
- The lastIndexOf() method of AbstractList class in Java
- The isEmpty() method of CopyOnWriteArrayList method in Java
- The hashCode() method of CopyOnWriteArrayList method in Java
- The clone() method of CopyOnWriteArrayList method in Java
- The contains() method of CopyOnWriteArrayList in Java
- The add() method of CopyOnWriteArrayList in Java
- The toString() method of CopyOnWriteArrayList in Java
- The set() method of CopyOnWriteArrayList in Java
- The addIfAbsent() method of CopyOnWriteArrayList in Java
- The iterator() method of CopyOnWriteArrayList in Java
- The listIterator() method of CopyOnWriteArrayList in Java
- The get() method of CopyOnWriteArrayList in Java
- Java String lastIndexOf() method example.
- The indexOf() method of CopyOnWriteArrayList class in Java

Advertisements