方法indexOf(obj o)在Java中做什么?
java.util.ArrayList类的 indexOf(Object)方法返回此列表中指定元素的首次出现的索引;如果此列表不包含该元素,则返回-1。
示例
import java.util.ArrayList;
public class ArrayListDemo {
public static void main(String[] args) {
ArrayList<String> arrlist = new ArrayList<String>(5);
arrlist.add("G");
arrlist.add("E");
arrlist.add("F");
arrlist.add("M");
System.out.println("Size of list: " + arrlist.size());
for (String value : arrlist) {
System.out.println("Value = " + value);
}
int retval=arrlist.indexOf("E");
System.out.println("The element E is at index " + retval);
}
}输出
Size of list: 4 Value = G Value = E Value = F Value = M The element E is at index 1
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短