Java LinkedList lastIndexOf() 方法
示例
查詢列表中專案的第一個和最後一個位置
import java.util.LinkedList;
public class Main {
public static void main(String[] args) {
LinkedList<String> cars = new LinkedList<String>();
cars.add("Volvo");
cars.add("Ford");
cars.add("BMW");
cars.add("Ford");
cars.add("Mazda");
System.out.println(cars.indexOf("Ford"));
System.out.println(cars.lastIndexOf("Ford"));
}
}
定義和用法
lastIndexOf()
方法返回列表中某個值最後一次出現的位置。如果列表中不存在該專案,則返回 -1。
語法
public int lastIndexOf(Object item)
引數值
引數 | 描述 |
---|---|
item | 必需。要在列表中搜索的項。 |
技術詳情
返回 | 列表中專案最後一次出現的位置,如果找不到該專案,則返回 -1。 |
---|
相關頁面
❮ LinkedList 方法