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 送给学长毕业祝福语简短