Difference between arraylist and linkedList [duplicate]

元气小坏坏 提交于 2019-12-09 14:57:53

问题


Possible Duplicate:
When to use LinkedList<> over ArrayList<>?
When to use a linked list over an array/array list?

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

When should I use TreeSet, LinkedHashSet and HashSet?


回答1:


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

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

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?

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



来源:https://stackoverflow.com/questions/11667955/difference-between-arraylist-and-linkedlist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!