Difference between arraylist and linkedList

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 ?


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.

链接地址: http://www.djcxy.com/p/19962.html

上一篇: 插入ArrayList vs LinkedList中间

下一篇: arraylist和linkedList之间的区别