方法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 老公开业祝福语简短
18 官宣新年祝福语简短