该toArray()
方法继承自该AbstractCollection()
方法。它返回一个包含此集合中相似元素的数组。
语法如下
public Object[] toArray()
要使用Java中的AbstractSequentialList类,您需要导入以下包
import java.util.AbstractSequentialList;
以下是toArray()
在Java中实现AbstractSequentialList方法的示例
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