Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

List.add Method (Object)

Visual Studio 2005

Inserts the specified element into a List object.

Package: java.util

Assembly: vjslib (in vjslib.dll)


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

Parameters

e

The element to be inserted into the List object.

true if the element is inserted successfully; false otherwise.

In this example, you create a linked list object, which implements the List interface through one of its super classes. Then you add some elements to the list and display them.

// list-add1.jsl
// List.add example

import java.util.*;

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

        // Add some elements:
        lList.add("My Node");
        lList.add("Your Node");
        lList.add(null);
        lList.add(new Integer(55));

        // Get and display the elements:
        for (int i=0; i<lList.size(); i++)
            System.out.println(lList.get(i));
    }
}

/*
Output:
My Node
Your Node
null
55
*/
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.