Collection and List are interfaces. ArrayList and LinkedList are actual implementations. There are many more classes that implements the Collection interface.Some of the methods takes a Collection object as an argument. For example if you have an ArrayList and want to add all the elements from a LinkedList to it, you can use the method addAll(Collection c). You don't even have to care whether it is the elements from a LinkedList you add or from
e.g. a HashSet.
In the Collections class (with an s at the end), there are methods that takes a List object as an argument. E.g. there are methods to reverse the orders in a List, and it doesn't matter if it is an ArrayList or LinkedList you pass in since they both implement List.
I think you would use LinkedList if you are mostly interested in accessing the elements in a sequential order, and the ArrayList when this is not the case (more like accessing an array).
Monday, February 25, 2008
what are the differences between List,Collection,ArrayList and LinkedList?
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment