
To get the size of Array we use the length() method but in ArrayList we use the size() method to find the size of ArrayList. We can make an Array as multi-dimensional but an ArrayList is always single dimensional. In Array we add the element by use assignment operator (=), But in ArrayList, we add the element by use of add() method. To iterate an ArrayList we can use for loop, forEach loop, Iterator, List Iterator. We can Iterate the Array by use of for loop, forEach loop. Here JVM converts the int to Integer type. Here ArrayList is can take only Integer type of data. Primitive and non-primitiveĪn Array can hold primitive(int, float, double) and non-primitive(String or User-defined class) data type.īut some developers misunderstood it and think ArrayList can take primitive data type also. It is mandatory to provide the size of the Array.Īn ArrayList is automatically initialized by default size 10. InitializationĪn Array should be initialized by some value. So ArrayList restrict the different type of data in generic ArrayList. By use of the generic concept, JVM ensures the type safety at compile time. But we should try to get errors at compile time.ĪrrayList supports the generic concept, unlike Array. If you add any incompatible element into an array, the compiler throws ArrayStoreException at run time. GenericĪn Array can’t be generic, it can hold a different type of element that checks on run time. It means all the differences between a List data structure and a Set data structure also apply to this pair. It automatically grows or shrinks when we add or remove elements. ArrayList vs HashSet Java The main difference between ArrayList and HashSet is that one is a List implementation while the other is a Set implementation. When we create an ArrayList it has default size i.e. It will throw ArrayIndexOutOfBoundException.Īn ArrayList has the dynamic size, it’s a growable array. If we try to add more elements than the size of the Array. The most popular difference between ArrayList and Array is size.Īn Array has fixed length and we can’t change the length after the creation of Array object.

Before moving further, you should read the Array in javaand ArrayList in java.

In this post, we will discuss the difference between ArrayList and array. In java ArrayList and array, both are famous data structure.
