第一种类型<String>之类的
List<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
list.add(4);
第二种类型<Object>对象
class Person{
String name;
String address;
public Person(String name, String address) {
this.name = name;
this.address = address;
}
}
List<Person> list2=new ArrayList<Person>();
Person person = new Person("tom", "北京");
Person person2 = new Person("jim","上海");
Person person3 = new Person("kim","宁波");
list2.add(person);
list2.add(person2);
list2.add(person3);
第三种Map< , >
Map<String, String> student = new HashMap<String, String>();
student.put("name", "tom");
student.put("address", "北京");
Set<String> keys= student.keySet();
Iterator<String> iterator=keys.iterator();
while(iterator.hasNext()){
System.out.println(iterator.next());
}
第四种与第二种效果一样,表达方式不同
List<Map<String,String>> list4 = new ArrayList<Map<String, String>>();
Map<String, String> map1 = new HashMap<String,String>();
map1.put("name","tom");
map1.put("address", "北京");
Map<String, String> map2 = new HashMap<String,String>();
map2.put("name","jim");
map2.put("address", "上海");
Map<String, String> map3 = new HashMap<String,String>();
map3.put("name","kim");
map3.put("address", "宁波");
list4.add(map1);
list4.add(map2);
list4.add(map3);