ArrayList
|
Array
|
ArrayList
is a variable length Collection class which means its size gets increased to
half of its capacity once its initial size is full.
|
Array
is fixed length data structure which means one cannot change its length after
creating the array object.
|
ArrayList can only contains objects.It cannot
contain primitive types i.e (int,float,long)
|
Arrays
can contain both objects as well as primitive types.
|
Apart from for and for
each loop,Iterator can also be used to iterate ArrayList.
|
For and for each loop
can be used to iterate over Arrays.
|
ArrayList is single
dimensional.
For ex:-
ArrayList<String>
a=new ArrayList<String>();
|
Arrays can have multi
dimensions also.
For ex:- Integer [][]
a=new Integer[3][3];
|
In ArrayList ,elements
are added using add(e) method.
For ex:- ArrayList<String>
a=new ArrayList<String>();
a.add(“robert”);
|
In Arrays,elements are
added using assignment operator.
For ex:-
Integer a[]=new
Integer[3];
a[0]=new Integer(1);
|
Enjoy Reading