提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
搜索ArrayList的元素
import java.util.ArrayList; /** 来 自 时 代 J a v a**/ public class Main { public static void main(String[] args) { ArrayList arrayList = new ArrayList(); arrayList.add("1"); arrayList.add("2"); arrayList.add("3"); arrayList.add("4"); arrayList.add("5"); arrayList.add("1"); arrayList.add("2"); boolean blnFound = arrayList.contains("2"); System.out.println("Does arrayList contain 2 ? " + blnFound);// 来自 n o w j a v a . c o m int index = arrayList.indexOf("4"); if(index == -1) System.out.println("ArrayList does not contain 4"); else System.out.println("ArrayList contains 4 at index :" + index); int lastIndex = arrayList.lastIndexOf("1");