Javatpoint Logo
Javatpoint Logo

Java Collections lastIndexOfSubList() Method

The lastIndexOfSubList() method of Java Collections class is used to get the starting position of the last occurrence of the specified target list within the specified source list. It returns -1 if there is no such occurrence in the specified list.

Syntax

Following is the declaration of lastIndexOfSubList() method:

Parameter

Parameter Description Required/Optional
source It is the list in which we search for the last occurrence of target. Required
target It is the list to search for as a subList of source. Required

Returns

The lastIndexOfSubList() method returns the starting position of the last occurrence of the specified target list within the specified source list, or -1 if there is no such occurrence.

Exceptions

NA

Compatibility Version

Java 1.4 and above

Example 1

Test it Now

Output:

Target Output: 2

Example 2

Test it Now

Output:

Target Output: -1

Example 3

Test it Now

Output:

List :[kitu, mani, raj, karthi, rahul, gagan]
Last IndexOfSubList: 3





Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA