ArrayList extends AbstractList and implements List interface, Cloneable, Serializable. ArrayList capacity grows automatically.
Java Collections Framework- ArrayList Class
ArrayList extends AbstractList and implements List interface, Cloneable, Serializable. ArrayList capacity grows automatically. The ArrayList is not synchronized. It permits all elements including null. ArrayList provides methods to manipulate the size of the array that is used internally to store the list. Array lists are created with an initial size. When this size is exceeded, the collection is automatically enlarged. When objects are removed, the array may be shrunk.
ArrayList has the constructors shown here:
- ArrayList( ) - Constructs an empty list with an initial capacity of ten.
- ArrayList(Collection c) - Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.
- ArrayList(int capacity) - Constructs an empty list with the specified initial capacity.
The following program shows a simple use of ArrayList
package devmanuals.com; import java.util.*; public class ArrayListDemo { public static void main(String[] args) { ArrayList ALST = new ArrayList(); ALST.add("One"); ALST.add("Three"); ALST.add("Two"); ALST.add("Four"); System.out.println("The ArrayList Elements are : " + ALST); } }
Output:
The ArrayList Elements are : [One, Three, Two, Four] |
Here is the more examples of ArrayList methods implementation.
[ 0 ] Comments