Export (0) Print
Expand All

LinkedList.toArray Method ()

Visual Studio 2005

Copies values of a LinkedList object to an array.

Package: java.util

Assembly: vjslib (in vjslib.dll)


public java.lang.Object[] toArray();

The array object.

// LList-toArr1.jsl
// LinkedList.toArray 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("Isabella");
        lList.add("Angelina");
        lList.add("Pille");
        lList.add("Hazem");

        // Create an array from the list:
        Object[] s = lList.toArray();

        // Display the array elements:
        System.out.println("The array elements are:");
        for (int i=0; i<lList.size(); i++)
            System.out.println(i + " = " + s[i]);
    }
}

/*
Output:
The array elements are:
0 = Isabella
1 = Angelina
2 = Pille
3 = Hazem
*/

Community Additions

ADD
Show:
© 2014 Microsoft