How to implement your own ArrayList?
************************************
-> ArrayList is a Resizable-array of an Objects.
In Array we don't have the capability of dynamically increasing the size of the array
but in ArrayList we can, We know that ArrayList has initial capacity of the element
to be added in a list, so first things we need is default initial capacity.
second things we need an Array of Objects to store the element of the ArrayList.
->Define default initial capacity of the CustomArrayList.
-private static final int DEFAULT_INITIAL_CAPACITY = 5;
->Now declare an empty CustomArrayList which will return while creating empty CustomArrayList
-private static final Object[] EMPTY_ELEMENT_DATA = {};
->Define the size for the CustomeArrayList
-private int size;
->Now we need to define an Array of an Object to store the elements view sourceprint?
-private transient Object[] customArrayListElementData;
So it is implementaion of ArrayList.
************************************
-> ArrayList is a Resizable-array of an Objects.
In Array we don't have the capability of dynamically increasing the size of the array
but in ArrayList we can, We know that ArrayList has initial capacity of the element
to be added in a list, so first things we need is default initial capacity.
second things we need an Array of Objects to store the element of the ArrayList.
->Define default initial capacity of the CustomArrayList.
-private static final int DEFAULT_INITIAL_CAPACITY = 5;
->Now declare an empty CustomArrayList which will return while creating empty CustomArrayList
-private static final Object[] EMPTY_ELEMENT_DATA = {};
->Define the size for the CustomeArrayList
-private int size;
->Now we need to define an Array of an Object to store the elements view sourceprint?
-private transient Object[] customArrayListElementData;
So it is implementaion of ArrayList.
Comments
Post a Comment