Different types of lists

Hi, I am learning Java, and I just got confused about the question that continues to appear on my exams.

We are told to use the class for our collections.

Usually in my main class I just create an arraylist of the type that I need, like bank accounts or something else. But I think we should make a class for all our data. I tried this and made them static and had an abstract class, because I do not need to make copies of the class itself.

What I want to know is why people just don’t make a type of list that can do everything the arrailist and list can do in one, why are there different types? What are the different types of benefits? Ps makes a collection just mean a class for all your data?

+7
java
source share
1 answer

Each list has its own use:

  • ArrayList behaves like a Resizable-array

  • LinkedList can be used as a FIFO queue

  • The stack is obviously a stack (LIFO)

Here's the javadoc for the list:

http://docs.oracle.com/javase/6/docs/api/java/util/List.html

+12
source share

All Articles