Export (0) Print
Expand All

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);

Parameters

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.

Community Additions

ADD
Show:
© 2014 Microsoft