list_remove Java · 集合方法
从 List 中删除元素;调用 remove(索引) 返回被删元素,调用 remove(对象) 返回 boolean。
怎么用
list.remove(索引) 或 list.remove(对象)
小例子
List<String> list = new ArrayList<>();
list.add("A");
String removed = list.remove(0);
System.out.println(removed);
运行结果
输出:A
提醒:List<Integer> 要按对象删除整数 1 时,请用 remove(Integer.valueOf(1)),否则会被当成索引
官方文档:https://docs.oracle.com/javase/8/docs/api/java/util/List.html
在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← Java全部词条