Java集合-Arraylist,Linklist,Hashset,Treeset,Hashmap,Treemap区分

Java集合分为三类:

  • List :存储可以自动扩展的数组
  • Set :存储没有重复元素的数组
  • Map:存储映射关系的关联数组

List分为:Arraylist和Linkedlist

-> Arraylist是可以自动扩展,长度可变,动态的数组数据结构,访问元素快,插入删除慢

创建集合的对象:
 ArrayList < Student> list=new ArrayList< Student>();
 遍历: 迭代器
Iterator< Student> it=list.iterator();//迭代器输出
            while(it.hasNext())
            {
                Student s=(Student) it.next();  //转换为Student类
                System.out.printf("%s %d\n",s.name,s.score);
        }

排序(->我的博客): 共两种方法(实现Comparator或者实现Comparable接口中的compareTo方法)
https://blog.csdn.net/qq_37486501/article/details/79999552

->Linkedlist是链表数据结构,访问元素慢,插入删除快
(方法同ArrayList)

Set分为:Hashset和Treeset

->Hashset未排序,存取速度快
(方法同ArrayList)
->Treeset已排序,可以通过实现实现Comparable接口实现自定义排序
(方法同ArrayList)

Map分为:Hashmap和Treemap

->Hashmap未排序

创建集合的对象:(自己定义key和value的类型)
 HashMap<String,Integer> map=new HashMap<String,Integer>();

排序(->我的博客): https://blog.csdn.net/qq_37486501/article/details/80141611
->Treemap已排序

猜你喜欢

转载自blog.csdn.net/qq_37486501/article/details/80141586