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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With