The toArray() method of AbstractSequentialList in Java


The toArray() method is inherited from the AbstractCollection() method. It returns an array containing similar elements in this collection.

The syntax is as follows

public Object[] toArray()

To work with the AbstractSequentialList class in Java, you need to import the following package

import java.util.AbstractSequentialList;

The following is an example to implement AbstractSequentialList toArray() method in Java

Example

 Live Demo

import java.util.LinkedList;
import java.util.AbstractSequentialList;
public class Demo {
   public static void main(String[] args) {
      AbstractSequentialList<Integer> absSequential = new LinkedList<>();
      absSequential.add(210);
      absSequential.add(290);
      absSequential.add(350);
      absSequential.add(490);
      absSequential.add(540);
      absSequential.add(670);
      absSequential.add(870);
      System.out.println("Elements in the AbstractSequentialList = "+absSequential);
      Object[] myArr = absSequential.toArray();
      System.out.println("Array = ");
      for (int i = 0; i < myArr.length; i++)
         System.out.println(myArr[i]); ;
   }
}

Output

Elements in the AbstractSequentialList = [210, 290, 350, 490, 540, 670, 870]
Array =
210
290
350
490
540
670
870

Updated on: 30-Jul-2019

46 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements