Q- What is the difference between Array and ArrayList?
Array | ArrayList |
Array is a fixed-length data structure. That means we cannot change the length of Array once created. |
ArrayList is a variable-length Collection class. ArrayList re-size itself when gets full depending upon the capacity and load factor. |
Array can contain both primitives and Objects |
We cannot store primitives in ArrayList. Only object can store. Though Autoboxing of Java 5 we can store primitives in ArrayList, it actually automatically converts primitives to Object. |
ArrayList can create an instance of ArrayList without specifying size. It will create Array List with default size |
It is mandatory to provide the size of Array while creating an instance. |
Performs faster than ArrayList because it is strongly typed. | Performs slows because of boxging and unboxing. |
Generics are not compatible with Arrays. | ArrayLists allow the use of Generics. |
Arrays can be multi-dimensional. | ArrayLists are single-dimensional only. |
The Length variable is used to determining an Array’s length. | Size() method is used to get the length of an ArrayList. |
Arrays take more memory for the storage of specified objects or elements. |
ArrayLists take less memory space for storing objects or elements. |
Iterating on Array takes less time then ArrayList. | Iterating on ArrayList takes more time, hence performance is slower. |
Related Tutorials
- Java Collections Interview
- List Interface In Java
- ArrayList
- Custom LinkedList implementation in java
- Custom Own ArrayList Implementation
- Set Interface In Java
- Map Interface In Java
- HashMap In Java
- HashMap Vs ConcurrentHashMap
- HashMap Vs HashTable In Java
- HashMap Vs HashSet In Java
- HashMap Vs TreeMap In Java
- HashMap vs LinkedHashMap In Java
- TreeSet Vs TreeMap In Java
- SortedSet Vs TreeSet In Java
- SortedMap Vs TreeMap In Java
- Array Vs ArrayList In Java
- ArrayList Vs LinkedList In Java
- How HashSet Works Internally
- How TreeMap Works Internally
- How HashMap Works Internally
- How ConcurrentHashMap Works Internally
- How To Detect Loop In A LinkedList In Java
- Detect And Remove Loop In A LinkedList
No comments:
Post a Comment