Related Examples
 

Java LinkedList indexOf Example

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


LinkedList class indexOf method example.public int indexOf(Object o) Returns the index of the first 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 indexOf method of LinkedList class in java.util package
 * version 15 May 2008
 * author Rose India 
 */
import java.util.*;

public class IndexOf {

    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("Index of the specified element in the LinkedList = " + list.indexOf("India"));
    }
}

Output
[0, Rose, India]
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