Praveen Kumar wrote:I do accept that Array List it self increases its size whenever the objects reaches its full capacity.
You seem to be confused about two different concepts - the ArrayList's
size and its
capacity.
The
size of the ArrayList changes whenever you add or remove an element to or from it. So you can decrease the size by simply removing one or more elements.
Internally, for efficiency reasons, the ArrayList allocates some space to store new elements (anticipating that you're going to add them later). This reserved space is the
capacity. How the capacity grows and shrinks depends on the implementation details of class ArrayList, and is something you normally don't need to be concerned with. If you want to know exactly how it works, you can lookup the source code of ArrayList in the file
src.zip that's in your JDK installation directory.