Difference between array and arraylist?
1) Array is Fixed length. ex String [] str=new string[10]
2) Arrays are strong type means you declare datatype at the time declaration.
3) To add simple element in array you need to find out last or position in that array and then you need to insert or add these element in that array.
4) So for above Problem ArrayList comes. ArrayList is present in System.Collection namespace. ex ArrayList arr=new ArrayList();
5) So by using arrayList interface is simplified ex arr.Add();/
6) In arraylist you can add any type of type in that object.
7) If you think in your project the collection is fixed type then use arrays – as compared to arraylist array are faster bcoz they are strong type.
8) If you want collection should resizable and generic then go for arraylist – as compared to array it is slower bcoz it accomodate an object and lots of boxing and unboxing happened their so thats why.
2) Arrays are strong type means you declare datatype at the time declaration.
3) To add simple element in array you need to find out last or position in that array and then you need to insert or add these element in that array.
4) So for above Problem ArrayList comes. ArrayList is present in System.Collection namespace. ex ArrayList arr=new ArrayList();
5) So by using arrayList interface is simplified ex arr.Add();/
6) In arraylist you can add any type of type in that object.
7) If you think in your project the collection is fixed type then use arrays – as compared to arraylist array are faster bcoz they are strong type.
8) If you want collection should resizable and generic then go for arraylist – as compared to array it is slower bcoz it accomodate an object and lots of boxing and unboxing happened their so thats why.
Comments
Post a Comment