Array and Array List

Java Programming for Selenium, Java Data Types, Modifiers, Variables, Operators, Control Flow, IO & File Handling, Arrays, Strings, Methods, Constructor and Exception Handling.
Java Object Oriented Programming concepts like Inheritance, Polymorphism, Abstraction and Encapsulation.
Post Reply
Posts: 142
Joined: Fri Nov 23, 2018 2:48 am

Array and Array List

Post by AyubHussain » Tue Nov 27, 2018 11:40 am

Difference between Array and Array List?

Posts: 62
Joined: Fri Nov 23, 2018 2:51 am

Re: Array and Array List

Post by dsusmitha » Tue Nov 27, 2018 11:52 am

Array :

1.Array is static

2.Size of the array should be given at the time of array declaration. We cannot change the size of array after creating it

3.Array can contain both primitive data types as well as objects

4.Arrays are multidimensional

Array List :

1.Array List is dynamic

2.Size of the array may not be required. It changes the size dynamically. Capacity of Array List increases automatically whenever we add elements to an Array List

3.Array List cannot contain primitive data types. It contains only objects

4.Array List is always single dimension

Posts: 55
Joined: Thu Jan 03, 2019 3:57 am

Re: Array and Array List

Post by kishore » Wed Jan 09, 2019 12:28 pm

Differences between Array and ArrayList:
1)An array is a basic functionality provided by Java. ArrayList is part of collection framework in Java. Therefore array members are accessed using [], while ArrayList has a set of methods to access elements and modify them.
2)Array is a fixed size data structure while ArrayList is not. One need not to mention the size of Arraylist while creating its object. Even if we specify some initial capacity, we can add more elements.
3)Array can contain both primitive data types as well as objects of a class depending on the definition of the array. However, ArrayList only supports object entries, not the primitive data types.
4)Since ArrayList can’t be created for primitive data types, members of ArrayList are always references to objects at different memory locations (See this for details). Therefore in ArrayList, the actual objects are never stored at contiguous locations. References of the actual objects are stored at contiguous locations.
In array, it depends whether the arrays is of primitive type or object type. In case of primitive types, actual values are contiguous locations, but in case of objects, allocation is similar to ArrayList.

Post Reply

Return to “Java for Selenium”