注意要导包,而且有相同名字的包,要看好属于哪一类,目前还没有学异常,会有黄色波浪线来提示
- package com.heima.list;
- import java.util.ArrayList;
- import java.util.List;
- public class Demo1_List {
- /**
- * * void add(int index,E element)
- * E remove(int index)
- * E get(int index)
- * E set(int index,E element)
- */
- public static void main(String[] args) {
- List list = new ArrayList();
- list.add("a");
- list.add("b");
- list.add("c");
- list.add("d");
- System.out.println(list);
- list.add(1,"x");
- System.out.println(list);
- list.add(5,"y");
- System.out.println(list);
- list.remove(1);
- System.out.println(list);
-
- System.out.println(list.get(1));
- list.set(1, "haha");
- System.out.println(list);
- for (int i = 0; i < list.size(); i++) {
- System.out.println(list.get(i));
- }
-
- }
- }
复制代码 |
|