Related Examples
 

Java LinkedList lastIndexOf Example

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


LinkedList class lastIndexOf method example.public 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 the code

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

public class LastIndexOf {

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

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

        System.out.println(list);
        System.out.println("Last index of the specified element " +
                "in the LinkedList = " + list.lastIndexOf("India"));
    }
}

Output
[0, Rose, India]
Last index of the specified element in the LinkedList = 2

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

HOME | COPYRIGHT | CONTACT US