Java 中 AbstractList 类中的 remove() 方法
使用 remove() 方法从列表中移除指定位置的元素。位置要作为方法自身中的索引参数设置。它返回被移除的元素。
语法如下
public E remove(int index)
这里,index 是你要从中删除元素的索引。
要使用 AbstractList 类,请导入以下包
import java.util.AbstractList;
以下是一个在 Java 中实现 AbstractlList 类的 remove() 方法的示例
示例
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(50);
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("Removing the element = " + myList.remove(5));
System.out.println("Elements in the updated AbstractList = " + myList);
}
}输出
Elements in the AbstractList = [50, 100, 150, 200, 250, 300, 350, 400] Removing the element = 300 Elements in the updated AbstractList = [50, 100, 150, 200, 250, 350, 400]
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP