Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 集合类 #13

Open
zhangsr opened this issue Dec 14, 2015 · 0 comments
Open

Java 集合类 #13

zhangsr opened this issue Dec 14, 2015 · 0 comments

Comments

@zhangsr
Copy link
Owner

zhangsr commented Dec 14, 2015

基础

常用分类:

  • List:ArrayList、LinkedList、Vector、Stack
  • Set:HashSet、LinkedHashSet、TreeSet
  • Map:HashMap、LinkedHashMap、TreeMap、HashTable

特点:

  • List:有序可重复
  • Set:不可重复
  • Map:键值对

List:

  • ArrayList:可变长数组
  • LinkedList:链表实现,插入删除效率高
  • Vector:线程安全的 ArrayList
  • Stack:Vector 的子类,多了堆栈操作的方法,方便

Set:

  • HashSet:为快速查找而生,基于 HashMap
  • LinkedHashSet:有序 HashSet,按插入顺序排列
  • TreeSet:有序 HashSet,按值排列

Map

  • HashMap:键值对结构
  • LinkedHashMap:有序 HashMap,按插入顺序排列
  • TreeMap:有序 HashMap,按值排列
  • HashTable:线程安全的 HashMap

选择流程图:

Tips

遍历:

  • for(int i; i < size; i++):效率低,每次通过get(i)获取都是O(n)
  • for(Object obj : objectList)
  • while (iteraotr.hasNext())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant