In above code I declared array size 2 that means we can store only 2 string values in array.
ArrayList:
1. ArrayList can store any type of items\elements.
2. ArrayList grows automatically and you don't need to specify size.
3. Items of ArrayList need to be cast to appropriate data type while retrieving.
Declaration of ArrayList
ArrayList strarr = new ArrayList(); strarr.Add("welcome"); // Add string values strarr.Add(10); // Add integer values strarr.Add(10.05); // Add float value
If you observe above code I haven’t mentioned any size in array list we can add all the required data there is no size limit and we will use add method to bind values to array list.
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Array:
1. Array is strongly typed. This means that an array can store only specific type of items\elements.
2. Array stores fixed number of elements. Size of an Array must be specified at the time of initialization.
3. No need to cast elements of an array while retrieving because it is strongly type and stores specific type of items only.
Declaration of Array
In above code I declared array size 2 that means we can store only 2 string values in array.
ArrayList:
1. ArrayList can store any type of items\elements.
2. ArrayList grows automatically and you don't need to specify size.
3. Items of ArrayList need to be cast to appropriate data type while retrieving.
Declaration of ArrayList
If you observe above code I haven’t mentioned any size in array list we can add all the required data there is no size limit and we will use add method to bind values to array list.