集合框架
- 在集合框架中,主要分为 Collection 和 Map 两大接口
- 在 Collection 中又分为 List (有序集合) 和 Set (无序集合)
注:List 和 Set 都是接口。 - List (有序集合) 和 Set (无序集合)的实现类又分别为ArrayList和HashSet
- Map 存储的 Key-Value 结构。
集合框架存储的元素可以是不定长的,即可以任意的添加,但是数组在定义的时候就确
定了长度。实际开发中,对于同类型数据的结构,一般使用 Collection 结构会较多。
三种遍历
for(int i =0;i < array.size();i++ ){
System.out.print(array.get(i).getName());
}
for(Student tmp : stu ){
System.out.print(tmp.getName)
}
Iterator<Student> it = stu.interator()
while(it.hasNext()){
Student tmp = it.next()
System.out.print(tmp.getName())
}