The first thing Arraylist and List can use to store any type of objects(integers, string).
ArrayList:
Consider your intended to store integer values just preferred Arraylist.
ArrayList objarraylist=new ArrayList();
objarraylist.Add(123);
objarrylist.Add("anil");//will compile but it throws run time error.
It will compile but not gives any error , while we iterate the Arraylist using foreach , it throws an run time error.
List:
List<int> obj=new List<int>();
obj.add(123);
obj.add("anil")// will result compile time error.
when we adding the object to the ArrayList at that time boxing is happens, while we retrieve the object from the ArrayList unboxing is done at that time , it will hurts the performance . in list there is no boxing and unboxing concept and also it has provide better type safety.
ArrayList:
Consider your intended to store integer values just preferred Arraylist.
ArrayList objarraylist=new ArrayList();
objarraylist.Add(123);
objarrylist.Add("anil");//will compile but it throws run time error.
It will compile but not gives any error , while we iterate the Arraylist using foreach , it throws an run time error.
List:
List<int> obj=new List<int>();
obj.add(123);
obj.add("anil")// will result compile time error.
when we adding the object to the ArrayList at that time boxing is happens, while we retrieve the object from the ArrayList unboxing is done at that time , it will hurts the performance . in list there is no boxing and unboxing concept and also it has provide better type safety.
No comments:
Post a Comment