105
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
Output:
Target Output: 2
Example 2
Output:
Target Output: -1
Example 3
Output:
List :[kitu, mani, raj, karthi, rahul, gagan] Last IndexOfSubList: 3
Next TopicJava Collections Class