package objectNextPart;
import java.util.ArrayList;
import java.util.List;
public class ArrayList1 {
public String add(String e) {
List<String> list = new ArrayList<String>();
list.add("aaa");
list.add("11");
list.add("nu");
list.add(e);
list.add(null);
System.out.println(list.size());
System.out.println(list.get(0) + "\n" + list.get(1));
System.out.println(list.get(2) + "\n" + list.get(3));
System.out.println(list.get(4));
list.set(2, "cqq");// 改变第三个对象
list.remove(1);// .remove(int index)移除索引为1(第二个对象),后面对象前移,索引-1
list.set(3, "hhh");
list.add(4, "aaaaaaaa");// .add(index)在指定索引处插入对象 ,原本对象后移,索引+1;
System.out.println("改变后的集合大小" + list.size());
System.out.println(list.get(0) + "\n" + list.get(1));
System.out.println(list.get(2) + "\n" + list.get(3));
System.out.println(list.get(4) + "\n" + list.get(5));
return list.get((int) (Math.random() * list.size()));// 随机生成[0,size()
// )的对象
}
public static void main(String[] args) {
ArrayList1 a1 = new ArrayList1();
// a1.add("ea");
System.out.println(a1.add("ea"));
}
}