what is difference between array and arraylist?

Posted by Bageshkumarbagi under ASP.NET on 10/19/2012 | Points: 10 | Views : 9571 | Status : [Member] | Replies : 3
hi ,
what is difference between array and arraylist?
give some example.

Thanks,
Bagesh Kumar Singh
Mark as answer if you have been satisfied



Responses

Posted by: Ranjeet_8 on: 10/19/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Array
-Array is of fixed size
-Array is the collection of values of the same data type
-Array mainly used to save variables of same data type
-The variables in an array is called array elements
-Array is a reference type data type

ArrayList
-ArrayList is allowed to grow as needed
-Array list are collection of objects of same type or different type.
-Its a Collection of Objects with Sorting Feature.
-Array list is used to store and retrieve the variables of different data type.
-Array list is a class .

The below is how we declare Array.

String [ ] str = new String [5]; // here you see that the length is fixed as [5] and the data type is also defined as string.

Now, see how you can declare ArrayList.

ArrayList str = new ArrayList (); // here you see that the length is not fixed and is not tied up with a data type.



Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 10/19/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Hi @Bageshkumarbagi
Please Mark As Answer if my post helps you.



Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Helen on: 10/23/2012 [Member] Starter | Points: 25

Up
0
Down
Arrays can store only primitives, that means no Strings, or Objects. However, an Array can store pointers to objects. While ArrayLists do not store primitives.you still can add primitives to an ArrayList by adding a wrapper class to the arraylist.Arrays are of fixed size. Whereas an ArrayList implements the list data structure and can dynamically grow.
Regards
helen
http://www.nitrotek.dk/


Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response