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
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿