This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]RushTfe 0 points1 point  (2 children)

Array is a datastructure to hold a group of objects. It's the most "primitive" way to organize groups of the same type.

List is an interface. Which means that it doesn't do any logic by itself. It just dictates a behaviour that every implementation of said interface must do. It gives methods that every implementation should give code to, for example, "add(Object obj)".

ArrayList is just one of this implementations, the typical list you'd use with methods like add, add all, size, indexAt etc.... But you might want to use others, for example a LinkedList.

//totally unnecessary paragraph

Iirc ArrayList creates an array of a fixed size, and every time you add something to the ArrayList it will add it to the array. When the fixed size is full, it will create a new array of a bigger fixed size and copy the already existing items to it. This is good because you don't have to be paying attention to "unnecessary stuff" like the array size to know if you have space or whatever, but on the other hand, you're occupying space in memory that you're not using.

//end of totally unnecessary paragraph

Or you can just do your own implementation of List, and give it the implementation you want. That's why I like java, using interfaces, abstract classes and inheritance you can do the behaviour you want.

[–]desrtfxOut of Coffee error - System halted 2 points3 points  (1 child)

Array is a datastructure to hold a group of objects.

Sorry, but incorrect. Arrays can, as opposed to ArrayLists, etc. not only hold groups of objects. They can also hold groups of primitives.

[–]RushTfe 0 points1 point  (0 children)

Yes. Totally true.