Array List

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

Array - fixed size, continous memory allocation(stores primitive data types like

int, float etc and objects , allocates memory in stack ) ArrayList -Memory non
continous, variable size (stores non primitive data types and allocates memory in
heap)
ArrayList is internally implemented by using a Dynamic array(once memory gets
filled in og array we double the size of the array and add new elements)
* ArrayList<int> is not possible but ArrayList<Integer> is . Integer is a wrapper
class and Integer objects have several methods but int variables dont have any
list.add(1);
list.add(12);
list.get(1); //get element at indx 1
list.add(3,1); // add element 1 at index 2
list.set(1,2); // set element at index 1 to 2
list.remove(1); // remove element at index 1
int size = list.size(); // get size of ArrayList
Collections.sort(list); //sort the list using Collections class, any
collections framework can be sorted using this class

You might also like