集合的小技巧

需要唯一吗?

  需要:Set

    需要制定顺序吗?

      需要:TreeSet

      不需要:HashSet

      但是想要一个和存储一致的顺序(有序):LinkedHashSet

  不需要:List

    需要频繁的增删吗?

      需要:LinkedList

      不需要:ArrayList

List

  |--ArrayList

  |--LinkedList

Set

  |--hashSet

  |--LinkedSet

后缀名就是该集合所属的体系。

前缀名就是该集合的数据结构。

array:数组,查询快,有角标

link:链表,增删快,add get remove+first last方法

hash:哈希表,唯一性,元素需要覆盖hashcode方法和equals方法

tree:二叉树,排序,两个接口Comparable Comparator两个接口

原文地址:https://www.cnblogs.com/hongcong/p/5878686.html