ArrayList Class

                                             
    java.lang.Object                                        
     |                                       
     |--java.util.AbstractCollection                                    
         |                                   
         |--java.util.AbstractList                                
             |                               
             |--java.util.ArrayList                            
                                             

The ArrayList class extends AbstractList and implements the List interface.

ArrayList supports dynamic arrays that can grow as needed.
An ArrayList is a variable-length array of object references.
An ArrayList can dynamically increase or decrease in size.

ArrayList has the constructors shown here:

This class is a member of the Java Collections Framework.

Constructor Summary

ArrayList()Creates an empty list with an initial capacity of ten.
ArrayList(Collection<? extends E> c) Creates a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.
ArrayList(int initialCapacity)Creates an empty list with the specified initial capacity.

Add to ArrayList

ReturnMethodSummary
booleanadd(E e)Appends the specified element to the end of this list.
voidadd(int index, E element)Inserts the specified element at the specified position in this list.
boolean addAll(Collection<? extends E> c) Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's Iterator.
boolean addAll(int index, Collection<? extends E> c) Inserts all of the elements in the specified collection into this list, starting at the specified position.

Clear an ArrayList

ReturnMethodSummary
voidclear()Removes all of the elements from this list.

Shallow copy of current ArrayList

ReturnMethodSummary
Objectclone()Returns a shallow copy of this ArrayList instance.

If contain a certain object

ReturnMethodSummary
booleancontains(Object o)Returns true if this list contains the specified element.

Increases the capacity of an ArrayList

ReturnMethodSummary
voidensureCapacity(int minCapacity)Increases the capacity of this ArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.

Get element by index

ReturnMethodSummary
Eget(int index)Returns the element at the specified position in this list.

Get object for index

ReturnMethodSummary
intindexOf(Object o)Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
intlastIndexOf(Object o)Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.

Remove from ArrayList

ReturnMethodSummary
Eremove(int index)Removes the element at the specified position in this list.
booleanremove(Object o)Removes the first occurrence of the specified element from this list, if it is present.

Replace element at index

ReturnMethodSummary
Eset(int index, E element)Replaces the element at the specified position in this list with the specified element.

Get the size and trim to size

ReturnMethodSummary
intsize()Returns the number of elements in this list.
voidtrimToSize()Trims the capacity of this ArrayList instance to be the list's current size.

If ArrayList is empty

ReturnMethodSummary
booleanisEmpty()Returns true if this list contains no elements.

Convert ArrayList to array

ReturnMethodSummary
Object[]toArray()Returns an array containing all of the elements in this list in proper sequence (from first to last element).
<T> T[] toArray(T[] a)Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.
Revised from Open JDK source code
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.