As the title say I am looking into the "Differences between an array and any collection from the java Collection framework".
Thought it's high level enough to provide some good understanding to a few (or many) of us who know too little about this or need to think far too long to come up with a interesting answer
So far, I have come up with:
Please correct me if these were incorrect assumptions, and of course add your own answers
Array is a fixed length data structure whereas ArrayList is a variable length Collection class. We cannot change length of array once created in Java but ArrayList can be changed. We cannot store primitives in ArrayList, it can only store objects.
What is an Array in Java ? An Array is collection of indexed and fixed number of homogeneous (same type) elements.
They are virtually unreleated, except to say they both store a group of values.
From a capability perspective, while both can store references to objects:
Integer
etc)One important difference, commonly not understood by programmers new to java, is one of usability and convenience, especially given that Collections automatically expand in size when needed:
Arrays are ultimately the only way of storing a group of primitives/references in one object, but they are the most basic option. Although arrays may give you some speed advantages, unless you need super-fast code, Collections are preferred because they have so much convenience.
There are 5 differences between Array and Collection as given below :
Arrays are fixed in size, whereas some Collections are grow-able in nature.
Arrays store homogeneous data. Collections store both homogeneous as well as heterogeneous data.
In Arrays, there are no underlining data structures, whereas Collections have underlining data structures.
Arrays are recommended for performance, whereas Collections are not.
Arrays use more memory space as compared to Collections.
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