题目描述:
创建一个List集合,并随意添加10个元素,然后返回索引为5处的元素;再获取其中某2个元素的索引,再删除索引为3的元素
-
import java.io.*;
-
import java.util.*;
-
public class cmd {
-
public static void main(String args[])
-
{
-
List books = new ArrayList();
-
for (int i = 0;i < 10;i++)
-
{
-
books.add(new String(String.valueOf(i*i)));
-
}
-
System.out.println(books.get(5));
-
System.out.println(books.indexOf("81"));
-
System.out.println(books.indexOf("100"));
-
System.out.println(books.remove(3));
-
System.out.println(books);
-
-
}
-
-
}
运行结果如下:
25
9
-1
9
[0, 1, 4, 16, 25, 36, 49, 64, 81]
阅读(1785) | 评论(0) | 转发(0) |