Difference between Array and ArrayList

The most important difference between Array and ArrayList is given below
ParameterArrayArrayList
1)DefinationArray 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)NatureArray is fixed in sizeArrayList is resizable or growable in size
4)Data StorageArray can store either of primitive or ObjectsArrayList can store only Objects
5)Data structureInternally Array does not follow any data structure so it does not have ready made method supportArrayList is part collection and internally its supports growable or resizable data structure so it has read made method support
6)Best ChoiceArray is best choice for search operation if we know the indexArrayList is best choice for search operation if we know the index
7)MemoryMemory wise array is worst choiceMemory wise ArrayList is good choice

You may also like...