

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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
<p>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.</p><p>The syntax is as follows</p><pre class="result notranslate">public int lastIndexOf(Object ob)</pre><p>Here, ob is the element. The return value would be the last index of this element.</p><p>To work with CopyOnWriteArrayList class, you need to import the following package</p><pre class="result notranslate">import java.util.concurrent.CopyOnWriteArrayList;</pre><p>The following is an example to implement CopyOnWriteArrayList class lastIndexOf() method in Java</p><h2>Example</h2><p><a class="demo" href="http://tpcg.io/ACEjSu" rel="nofollow" target="_blank"> Live Demo</a></p><pre class="prettyprint notranslate">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)); } }</pre><h2>Output</h2><pre class="result notranslate">CopyOnWriteArrayList = [50, 90, 500, 200, 350, 500, 650] The last index of element 500 = 5</pre>
- Related Questions & Answers
- 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