The lastIndexOf() method in org.javatuples is used to find the last index of a value, passed as parameter, in TupleClass. This method takes the parameter of Object type, so that it can check for all type of values. It is inherited from the JavaTuple class. This method can be used to any tuple class object of javatuples library. It returns an int which is the last index of the value passed as the parameter, if found more than once. If found just once, it returns that index. And if not found, then it returns -1.
public final int lastIndexOf(Object value)
int index = TupleClassObject.lastIndexOf(Object value)
Here TupleClassObject represents the JavaTuple Class object used like Unit, Quintet, Decade, etc.
Return Value: This method returns an int which is the last index of the value passed as the parameter, if found more than once. If found just once, it returns that index. And if not found, then it returns -1.
Below are programs that will illustrate the various ways to use lastIndexOf() method:
Program 1: Using lastIndexOf() with Unit class:
Last Index of GeeksforGeeks = 0 Last Index of Present = -1
Program 2: Using lastIndexOf() with Quartet class:
Last Index of 1 = 2 Last Index of GeeksforGeeks = 3 Last Index of 20.5 = -1
Note: Similarly, it can be used with any other JavaTuple Class.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.