Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

List.contains Method

Visual Studio 2005

Checks if a List object contains a specific element.

Package: java.util

Assembly: vjslib (in vjslib.dll)


public abstract boolean contains(
    java.lang.Object e);

Parameters

e

The element searched for in the List object.

true if the element was found; false otherwise.

In this example, you create and initialize a linked list object, and then you check to see if the list contains a specified element.

// list-cont1.jsl
// List.contains 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("Your Node");
        lList.add(null);
        lList.add(new Integer(55));

        // Check if "My Node" is in the list:
        if(lList.contains("My Node"))
            System.out.println(
                       "The object \"My Node\" is in the list.");
    }
}

/*
Output:
The object "My Node" is in the list.
*/
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.