Want create site? Find Free WordPress Themes and plugins.

Both Array and ArrayList are two important used structure in Java and frequently used in Java programs. Even though ArrayList is internally backed by an array, knowing the difference between an array and an ArrayList in Java is critical for becoming a good Java developer. If you know the similarity and differences, you can judiciously decide when to use an array over an AraryList or vice-versa. 

  • Array is a basic data structure which is the part of Java from the beginning.

  • ArrayList is a class in Java Collection Framework which is introduced from JDK 1.2. 

Differences Between Array And ArrayList In Java :

 ArrayArrayList
ResizableArray is static in size that is fixed length data structure, One can not change the length after creating the Array object.ArrayList is dynamic in size . Each ArrayList object has instance variable capacity which indicates the size of the ArrayList. As elements are added to an ArrayList its capacity grows automatically.
 IterateWe can use for loop or for each loop to iterate through arrayWe can use iterator  to iterate through ArrayList . The iterators returned by the ArrayList class’s iterator and listiterator method are fail-fast.
 Data TypeArray can contain both primitive data types as well as objects of a class depending on the definition of the array.ArrayList only supports object entries, not the primitive data types.
 Length Length of the ArrayList is provided by the size()Each array object has the length variable which returns the length of the array. 
 Adding elementsIn array we insert elements using the assignment operator. We can insert elements into the arraylist object using the add() method.
 Multi-dimensionalArray can be multi dimensional.ArrayList is always single dimensional

 Thanks in advanced for sharing… Sharing is caring…

Did you find apk for android? You can find new Free Android Games and apps.

Leave a Comment

1 Comment