Array Vs Arraylist in Java - Difference between Array and Arraylist



Array Vs Arraylist in Java - Difference between Array and Arraylist

Comparison Index Array Arraylist
DefinitionAn array is a dynamically-created object.
It serves as a container that holds the constant
number of values of the same type. It has
a contiguous memory location.
The ArrayList is a class of Java Collections framework. It contains popular classes like Vector, HashTable, and HashMap.
Dimensionality It can be single-dimensional or multidimensional It can only be single-dimensional
ResizableAn array is a fixed-length data structure.ArrayList is a variable-length data structure. It can be resized itself when needed.
Traversing Elements For and for each generally is used for iterating
over arrays
Here iterator is used to traverse over ArrayList
Lengthlength keyword can give the total size of the array.size() method is used to compute the size of ArrayList.
SizeIt is static and of fixed length.It is dynamic and can be increased or decreased in size when required.
SpeedIt is faster as above we see it of fixed sizeIt is relatively slower because of its dynamic nature
Primitive/ Generic typeAn array can store both objects and primitives type.We cannot store primitive type in ArrayList. It automatically converts primitive type to object.
Adding ElementsThe additions are done with the assignment operator.ArrayList uses add() method for performing additions

Related Searches to Array Vs Arraylist in Java - Difference between Array and Arraylist