Home » Java CopyOnWriteArrayList lastIndexOf() Method with Examples

Java CopyOnWriteArrayList lastIndexOf() Method with Examples

by Online Tutorials Library

Java CopyOnWriteArrayList lastIndexOf(E e, int index) Method

The lastIndexOf(E e, int index) method of Java CopyOnWriteArrayList class returns the index of the last occurrence of the specified element in this list which is searched backward from the index. If the element is not found, this method will return -1.

Syntax:

Parameters:

e – element to search for

index – index to start searching backward from

Returns:

This method returns the index of the last occurrence of the element at a position less than or equal to index in this list. This method returns -1 if the element is not found.

Example 1

Test it Now

Output:

Last Index of 3 is : 6  

Example 2

Test it Now

Output:

Last Index of 11 is : -1  

Example 3

Test it Now

Output:

Last Index of John is : 4  

Example 4

Test it Now

Output:

Last Index of Lincoln is : -1  

You may also like