数组列表和链接列表的区别 [英] Difference between arraylist and linkedList

查看:32
本文介绍了数组列表和链接列表的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
何时使用 LinkedList<>在 ArrayList<>?
何时在数组上使用链表/数组列表?

什么时候应该使用arrayList,什么时候应该使用LinkedList?

When should I use arrayList and when should I go for LinkedList?

我应该什么时候使用TreeSetLinkedHashSetHashSet?

When should I use TreeSet, LinkedHashSet and HashSet?

推荐答案

When should i use arrayList and when should I go for LinkedList?

Arraylist 像数组一样维护索引.因此,如果想要比 put 更频繁的 get 操作,那么最好使用 arraylist.

Arraylist maintain indices like arrays. So if want more frequent get operations than put then arraylist is best to go.

LinkedList 维护指向元素的指针.你不能像在 arraylist 中那样使用特定的索引.但是在链表中的优点是它们不需要像在数组列表中那样来回移动来维护连续索引.因此,链表中的 get 操作成本很高,因为您必须通过指针才能到达您的元素.但是 put 操作比 arraylist 好.你只需要连接到指针就可以了.

LinkedList maintain pointers to elements. you can't to a specific index like in arraylist. But the advantage here in linkedlist is that they don't need to shift back and forth like in arraylist to maintain continues indices. So get operations in linkedlist are costly as you would have to go through pointers to reach your elements. But put operations are good as compared to arraylist. you just need to connect to pointers and that's it.

When should I use TreeSet, LinkedHashSet and HashSet?

区别仅在于排序.treeset 元素需要维护由您的成员对象定义的特定顺序.

the difference is only in ordering. treeset elements need to maintain a specific orders defined by your member objects.

这篇关于数组列表和链接列表的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆