The most important difference between Array and ArrayList is given below
Parameter
Array
ArrayList
1)Defination
Array is similar to variable only thing is that it can hold more than one value at time. Array stores homogeneous(mean same type like int or float or char etc) data.
ArrayList is similar to variable only thing is that it can hold more than one value at time. ArrayList stores homogeneous(mean same type like int or float or char etc) data as well as hetrogeneous(different type of data like int, string char all together) data.
2)Example
public class ArrayExample
{
public static void main(String[] args)
{
//Array is storing int type of data(homogeneous)
int[] data= {1,2,3,4,5,6};
for(int i:data)
System.out.println(i);
}
}
import java.util.ArrayList;
public class ArrayListExample
{
public static void main(String[] args)
{
ArrayList data=new ArrayList();
//Array is storeing int, String, double type data (means hetrogeneous data)
data.add(1);
data.add("test");
data.add(10.5);
System.out.println(data);
}
}
3)Nature
Array is fixed in size
ArrayList is resizable or growable in size
4)Data Storage
Array can store either of primitive or Objects
ArrayList can store only Objects
5)Data structure
Internally Array does not follow any data structure so it does not have ready made method support
ArrayList is part collection and internally its supports growable or resizable data structure so it has read made method support
6)Best Choice
Array is best choice for search operation if we know the index
ArrayList is best choice for search operation if we know the index