Java LinkedList removeFirst() 方法
示例
移除列表中的第一个元素
import java.util.LinkedList;
public class Main {
public static void main(String[] args) {
LinkedList<String> cars = new LinkedList<String>();
cars.add("Volvo");
cars.add("BMW");
cars.add("Ford");
cars.add("Mazda");
// Use removeFirst() remove the first item from the list
cars.removeFirst();
System.out.println(cars);
}
}
定义和用法
removeFirst()
方法移除列表中的第一个元素。
提示:使用 removeLast()
方法移除列表中的最后一个元素。
语法
public T removeFirst()
T
指的是列表中项的数据类型。
参数
无。
技术详情
返回 | 被移除的元素(列表中的第一个元素) |
---|---|
抛出 | NoSuchElementException - 如果列表为空。 |
相关页面
❮ LinkedList 方法