Example usage for java.util LinkedList lastIndexOf

List of usage examples for java.util LinkedList lastIndexOf

Introduction

In this page you can find the example usage for java.util LinkedList lastIndexOf.

Prototype

public int lastIndexOf(Object o) 

Source Link

Document

Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.

Usage

From source file:Main.java

public static void main(String[] args) {
    LinkedList<String> lList = new LinkedList<String>();
    lList.add("1");
    lList.add("2");
    lList.add("3");
    lList.add("4");
    lList.add("5");
    lList.add("2");

    System.out.println(lList.indexOf("2"));

    System.out.println(lList.lastIndexOf("2"));

}

From source file:Main.java

public static void main(String[] args) {

    // create a LinkedList
    LinkedList<String> list = new LinkedList<String>();

    // add some elements
    list.add("Hello");
    list.add("from java2s.com");
    list.add("10");

    // print the list
    System.out.println("LinkedList:" + list);

    // get the last index for "Hello"
    System.out.println("Index for Hello:" + list.lastIndexOf("Hello"));

    // get the index for "Coffee"
    System.out.println("Index for Coffee:" + list.indexOf("Coffee"));
}