什么时候应该使用arrayList,什么时候应该使用LinkedList?
我应该什么时候使用TreeSet
,LinkedHashSet
和HashSet
?
什么时候应该使用arrayList,什么时候应该使用LinkedList?
我应该什么时候使用TreeSet
,LinkedHashSet
和HashSet
?
When should i use arrayList and when should I go for LinkedList?
Arraylist 像数组一样维护索引。因此,如果想要比 put 更频繁的 get 操作,那么最好使用 arraylist。
LinkedList 维护指向元素的指针。你不能像在arraylist中那样指定一个特定的索引。但是linkedlist的优势在于它们不需要像在arraylist中那样来回移动来维护连续索引。因此,链表中的获取操作成本很高,因为您必须通过指针才能访问您的元素。但是与 arraylist 相比,put 操作是好的。你只需要连接到指针就可以了。
When should I use TreeSet, LinkedHashSet and HashSet?
区别仅在于订购。treeset 元素需要维护由您的成员对象定义的特定顺序。