Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different types of lists [closed]

Tags:

java

Hello I am studying Java and I am just confused about a question that keeps coming up in my exams.

We are told to use a class for our collections.

Usually in my main class I just make an arraylist of the type I need like bank accounts or whatever. But I think we are supposed to make a class for all our data. I tried this and made them static and have the class abstract because I don't need to make copies of the class itself.

What I want to know is why don't people just make a list type that can do everything an arraylist and list can do in one, why is there different types? What are the benifits of having different types? Ps does a collection just mean a class for all your data?

like image 551
Sam Avatar asked Aug 17 '13 16:08

Sam


1 Answers

Every List has its own usage:

  • ArrayList behaves like a Resizable-array

  • LinkedList could be used as a FIFO queue

  • Stack obviously is a stack (LIFO)

Here's the javadoc for list:

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

like image 165
Mingyu Avatar answered Oct 12 '22 02:10

Mingyu