Java中AbstractSequentialList的clear()方法
该clear()方法从AbstractList类继承。它允许您从列表中删除所有元素。
语法如下
public void clear()
要使用Java中的AbstractSequentialList类,您需要导入以下包
import java.util.AbstractSequentialList;
以下是clear()在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(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 = []
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短