Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

what are the differences between List,Collection,ArrayList and LinkedList?

0
Posted

what are the differences between List,Collection,ArrayList and LinkedList?

0

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).

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.