区别

2012-07-26 18 views
3

可能重复:
When to use LinkedList<> over ArrayList<>?
When to use a linked list over an array/array list?区别

什么时候应该使用ArrayList,当我应该去LinkedList的?

什么时候应该使用TreeSet,LinkedHashSetHashSet

+3

欢迎来到Stack Overflow!我们鼓励你[研究你的问题](http://stackoverflow.com/questions/how-to-ask)。如果你已经[尝试了某些东西](http://whathaveyoutried.com/),请将其添加到问题中 - 如果没有,请先研究并尝试您的问题,然后再回来。 – 2012-07-26 11:09:47

+1

另请参阅[Hashset vs Treeset](http://stackoverflow.com/questions/1463284/hashset-vs-treeset)和[HashSet vs LinkedHashSet](http://stackoverflow.com/questions/5080612/hashset-vs- linkedhashset)关于你的第二个问题。 – 2012-07-26 11:10:47

回答

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

ArrayList中保持像数组索引。所以如果想要比操作更频繁的操作,那么ArrayList是最好的选择。

LinkedList维护指向元素的指针。你不能像arraylist中的特定索引。但是链表中的优势在于它们不需要像数组列表那样来回移动以保持连续索引。所以在链表中获得操作代价很高,因为你必须通过指针来达到你的元素。但是与数据列表相比,放置操作是很好的。你只需要连接到指针,就是这样。

When should I use TreeSet, LinkedHashSet and HashSet? 

区别只在于订购。 treeset元素需要维护由成员对象定义的特定顺序。