AbstractSequentialList类的get()方法用于在此列表中的指定位置显示元素。
语法如下
public E get(int index)
在这里,索引是您要从中获取元素的位置。
要使用Java中的AbstractSequentialList类,您需要导入以下包
import java.util.AbstractSequentialList;
以下是在Java中实现AbstractSequentialList get()方法的示例
import java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo { public static void main(String[] args) { AbstractSequentialList<Integer> absSequential = new LinkedList<>(); absSequential.add(10); absSequential.add(25); absSequential.add(60); absSequential.add(70); absSequential.add(195); System.out.println("Elements in the AbstractSequentialList = "+absSequential); System.out.println("Element at index 2 = " + absSequential.get(2)); System.out.println("Element at index 4 = " + absSequential.get(4)); } }
输出结果
Elements in the AbstractSequentialList = [10, 25, 60, 70, 195] Element at index 2 = 60 Element at index 4 = 195