toArray Method ()
Collapse the table of content
Expand the table of content
The document is archived and information here might be outdated

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
*/
Show:
© 2016 Microsoft