Java 中 AbstractSequentialList 的 toArray() 方法
toArray() 方法继承于 AbstractCollection() 方法。它返回一个包含此集合中类似元素的数组。
语法如下
public Object[] toArray()
要在 Java 中使用 AbstractSequentialList 类,你需要导入以下包
import java.util.AbstractSequentialList;
以下示例演示如何在 Java 中实现 AbstractSequentialList toArray() 方法
示例
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]); ; } }
输出
Elements in the AbstractSequentialList = [210, 290, 350, 490, 540, 670, 870] Array = 210 290 350 490 540 670 870
广告