- <div class="blockcode"><blockquote>
- public class ListTest {
- public static void main(String[] args){
- Person p1 = new Person("张三",20);
- Person p2 = new Person("李四",21);
- Person p3 = new Person("王五",22);
-
- List list = new ArrayList();
-
- list.add(new Person("赵六",23));
- System.out.println(list.get(0));
- System.out.println(list.get(1));
- System.out.println(list.get(2));
- System.out.println(list.get(3));
- System.out.println(list.size());
- }
- }<blockquote>
复制代码 list.add是添加元素,
上面的Person p1 = new Person("张三",20);
和它的区别是什么?
我在下面获取了4个角标上的内容,以及长度,
但是会报错,只有0角标上有内容,求解~
|