E就是泛型- package Junit;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.List;
- import org.junit.Test;
- public class Test5 {
- @Test
- public void cry() {
- List<Person> list = new ArrayList<Person>();
- list.add(new Person("张三", 1));
- list.add(new Person("李四", 2));
- list.add(new Person("王五", 3));
- list.add(new Person("赵六", 4));
- Iterator<Person> it = list.iterator();
- while (it.hasNext()) {
- Person p = it.next();
- System.out.println("姓名:\t" + p.getUsername() + "\t" + "编号:\t"
- + p.getId());
- }
- }
- }
复制代码 |