Java中AbstractList类的clear()方法
使用clear()AbstractList类的方法从列表中删除所有元素。使用该方法后,列表将没有任何元素。
语法如下
public void clear()
要使用AbstractList类,请导入以下包
import java.util.AbstractList;
以下是clear()在Java中实现AbstractlList类的方法的示例
示例
import java.util.ArrayList;
import java.util.AbstractList;
public class Demo {
public static void main(String[] args) {
AbstractList<Integer>
myList = new ArrayList<Integer>();
myList.add(75);
myList.add(100);
myList.add(150);
myList.add(200);
myList.add(250);
myList.add(300);
myList.add(350);
myList.add(400);
System.out.println("Elements in the AbstractList = " + myList);
System.out.println("Count of Elements in the AbstractList = " + myList.size());
myList.clear();
System.out.println("\nElements in the updated AbstractList = " + myList);
System.out.println("Count of Elements in the updatedAbstractList = " + myList.size());
}
}输出结果
Elements in the AbstractList = [75, 100, 150, 200, 250, 300, 350, 400] Count of Elements in the AbstractList = 8 Elements in the updated AbstractList = [] Count of Elements in the updatedAbstractList = 0
热门推荐
10 朋友新年祝福语大全 简短
11 新年祝福语简短大方兔年
12 搬新家礼物祝福语简短
13 同学见面花束祝福语简短
14 五一假期祝福语幽默简短
15 离职欢送敬酒祝福语简短
16 对学弟的祝福语简短
17 考老师辞职祝福语简短
18 祝福语驱散霉运的话简短