What is the difference between Array and ArrayList is quite a common question among beginners especially those who started coding in C and C++ and prefer to use Array? Both Array and Array List are used to store elements, which can be either primitive or objects in case of Array and only objects in case of ArrayList in Java. The main difference between Array vs ArrayList in Java is the static nature of the Array and the dynamic nature of ArrayList. Once created you can not change the size of Array but ArrayList can re-size itself when needed. Another notable difference between ArrayList and Array is that Array is part of core Java programming and has special syntax and semantics support in Java, While ArrayList is part of the Collection framework along with other popular classes like Vector, Hashtable, HashMap or LinkedList.
Let's see some more difference between Array and ArrayList in Java in point form for better understanding.
Let's see some more difference between Array and ArrayList in Java in point form for better understanding.
Array vs ArrayList in Java
1) First and Major difference between Array and ArrayList in Java is that Array is a fixed length data structure while ArrayList is a variable length Collection class. You can not change length of Array once created in Java but ArrayList re-size itself when gets full depending upon capacity and load factor. Since ArrayList is internally backed by Array in Java, any resize operation in ArrayList will slow down performance as it involves creating new Array and copying content from old array to new array.
2) Another difference between Array and ArrayList in Java is that you can not use Generics along with Array, as Array instance knows about what kind of type it can hold and throws ArrayStoreException, if you try to store type which is not convertible into type of Array. ArrayList allows you to use Generics to ensure type-safety.
3) You can also compare Array vs ArrayList on How to calculate length of Array or size of ArrayList. All kinds of Array provides length variable which denotes length of Array while ArrayList provides size() method to calculate size of ArrayList in Java.
4) One more major difference between ArrayList and Array is that, you can not store primitives in ArrayList, it can only contain Objects. While Array can contain both primitives and Objects in Java. Though Autoboxing of Java 5 may give you an impression of storing primitives in ArrayList, it actually automatically converts primitives to Object. e.g.
ArrayList<Integer> integerList = new ArrayList<Integer>();
integerList.add(1); //here we are not storing primitive in ArrayList, instead autoboxing will convert int primitive to Integer object
integerList.add(1); //here we are not storing primitive in ArrayList, instead autoboxing will convert int primitive to Integer object
5) Java provides add() method to insert element into ArrayList and you can simply use assignment operator to store element into Array e.g. In order to store Object to specified position use
Object[] objArray = new Object[10];
objArray[1] = new Object();
objArray[1] = new Object();
6) One more difference on Array vs ArrayList is that you can create instance of ArrayList without specifying size, Java will create Array List with default size but its mandatory to provide size of Array while creating either directly or indirectly by initializing Array while creating it. By the way you can also initialize ArrayList while creating it.

Further Learning
Java In-Depth: Become a Complete Java Engineer
Java Fundamentals: Collections
Data Structures and Algorithms: Deep Dive Using Java
Other Java ArrayList Tutorials you may find useful
Very informative! Thumbs up!
ReplyDeletevery good
ReplyDeleteGood Tutorial , keep it up
ReplyDeletethanks
Very good Tutorial,keep it up .
ReplyDeleteThank you
good
ReplyDeletevery very good tutorial
ReplyDeleteVery helpful and straight to the point. Thanks a bunch!
ReplyDeleteVery Helpful thanks
ReplyDeleteMakes sense:)
ReplyDeleteNice explanations
ReplyDeletenice one dude..keep it up
ReplyDeletethis gud
ReplyDeletethanks
ReplyDeletevgood
ReplyDeleteVery good dude, thumbs up!
ReplyDeleteMake sense dude. Im Arjay.
ReplyDeleteThank you.
ReplyDeletegood
ReplyDeletethanks from the future :)
ReplyDeletewelcome from the present :-)
DeleteThanks for sharing this once again..
ReplyDelete