Wednesday, November 25, 2015

Difference Between Array, Arrays and ArrayList

Difference Between Array, Arrays and ArrayList



Array
Arrays
ArrayList
Package


package java.util;

package java.util;
List Interface
Defination
Array is part of core Java programming and has special syntax and semantics support in Java.


This class contains various methods for manipulating arrays (such as sorting and searching). This class also contains a static factory that allows arrays to be viewed as lists.
ArrayList is part of Collection framework along with other popular classes e.g. Vector, Hashtable, HashMap or LinkedList.
Syntax

int arr[]=new int();
Arrays.sort(arr)
ArrayList<String> list=new ArrayList<String>();
Size
Array is  fixed length data structure.

Length of array cannot changed once it created.


ArrayList is a variable length Collection class.
Resizing operation in ArrayList is slow down performance as it creates new Array and copying content from old Array to new Array.

Generics
Array doesn’t support the Generics, as Array instance knows about what kind of type it can hold and throws ArrayStoreException.

ArrayList allows you to use Generics to ensure type-safety.
MultiDimential
Array can be multi-dimensional.

Array list is single dimensional.
Wrapper
Array allows to store both primitives and Objects in Java.

ArrayList doesn’t allow to store primitives in ArrayList, it can only contain Objects.

No comments:

Post a Comment