Java ArrayList lastIndexOf Example

ArrayList class lastIndexOf method example. This example shows you how to use lastIndexOf method.


ArrayList class lastIndexOf method example.int lastIndexOf(Object o) Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.

Here is code

/**
 * @ # lastIndexOf.java
 * A class repersenting use to lastIndexOf method of ArrayList class in java.util package
 * version 14 May 2008
 * author Rose India 
 */
import java.util.*;

public class LastIndexOf {

    public static void main(String args[]) {
        List arrlist = new ArrayList();
        int i = 0;
        String str = "Rose";

        //Add the specified element to the end of this list.
        arrlist.add(i);
        arrlist.add(str);
        arrlist.add("India");

        System.out.println("arrlist = " + arrlist);
        System.out.println("Index of the last occurrence of the specified element " + arrlist.lastIndexOf("Rose"));

    }
}

Output
arrlist = [0, Rose, India]
Index of the last occurrence of the specified element 1

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US