In Java, I don’t understand a collection vs a ‘data structure’. It seems to me that collection refers to list, set, map, queue, and ‘data structure’ refers to the data structure used to implement the collection such as an array, linked list, or tree. For example ArrayList and LinkedList are both collection, but their data structure are respectively an array, and a linked list. Am I correct, or am I confusing terms?
Share
A data structure is how the data is represented inside the storage in memory. A collection is how it can be accessed. I stress on the word “can”.
If you store data in a LinkedList and sort it, the performance will drop. The same algorithm if you use a ArrayList the performance will enhance. Just by changing the way its represented in memory will help various factors.
You “can” access it using a collection representation, you “can” also use the “index” to access the data. You “can” also go getFirst, getNext, getPrev.
Your confusion is between internal storage and accessing the storage. Separate the 2.