Java 中的 AbstractSequentialList 的 clear() 方法
clear() 方法从 AbstractList 类继承而来。它允许你从列表中移除所有元素。
语法如下
public void clear()
为了使用 Java 中的 AbstractSequentialList 类,你需要导入以下包
import java.util.AbstractSequentialList;
下面是一个在 Java 中实现 AbstractSequentialList clear() 方法的示例
示例
import java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo { public static void main(String[] args) { AbstractSequentialList<Integer> absSequential = new LinkedList<>(); absSequential.add(250); absSequential.add(320); absSequential.add(400); absSequential.add(550); absSequential.add(600); absSequential.add(700); absSequential.add(900); System.out.println("Elements in the AbstractSequentialList = "+absSequential); System.out.println("Does the element exist? = " + absSequential.contains(400)); absSequential.clear(); System.out.println("Elements in the updated AbstractSequentialList = "+absSequential); } }
输出
Elements in the AbstractSequentialList = [250, 320, 400, 550, 600, 700, 900] Does the element exist? = true Elements in the updated AbstractSequentialList = []
广告