This documentation is archived and is not being maintained.

List.indexOf Method

Visual Studio 2005

Retrieves the index of a specific element in a List.object.

Package: java.util

Assembly: vjslib (in vjslib.dll)

public abstract int indexOf(
    java.lang.Object e);



The elements for which the index is retrieved.

The index of the element.

// list-idxOf1.jsl
// List.indexOf example

import java.util.*;

public class MyClass
    public static void main(String[] args)
        // Create a linked list object:
        LinkedList lList =  new LinkedList();

        // Add some elements:
        lList.add("My node");
        lList.add("Her node");
        lList.add("Their node");
        lList.add("Your node");

        // Print the index of "Your node":
        System.out.println("The index is: " + 
                           lList.indexOf("Your node"));

The index is: 3

If the element is not found it returns -1.