Java - Collection - ArrayList
ArrayList:
- It extends AbstractList
- It implements List, RandomAccess, Cloanable, Serializable
- Resizable-array implementation of the List interface.
- Duplicate Allowed
- Insertion Ordered Maintained
- Constant time for this methods -> size, isEmpty, get, set
- O(n) time for this method -> add
- Capactiy - Capacity is the size of the array used to store elements in the list
- Using ensureCapacity application can increase the capacity of an ArrayList Instance
- If inital capacity is not provided then default capacity is 10.
- int newcapacity = oldcapacity + (oldcpacity >> 1 ) ; For Example : oldcapacity =10 ; then newcapacity = 15
- When elements are removed, gap will be created. Then need to shift subsequenct element in the left using below,
System.arraycopy( elementData, index+1, elementData, index, numMoved )
Comments
Post a Comment