
9.7 The ArrayList Class 613
9.7.3 Looping Through an ArrayList Using an Enhanced for Loop
The general pattern for processing elements of an ArrayList of ClassName
objects called arrayListName using a for loop is
ClassName currentObject;
for ( int i = 0; i < arrayListName.size(); i++ )
{
currentObject = arrayListName.get( i );
// process currentObject
}
TABLE 9.5 ArrayList Methods
Useful Methods of the ArrayList Class
Return value Method name and argument list
boolean add( E
element )
appends the specified element to the end of the list
void clear( )
removes all the elements from this list
int size( )
returns the number of elements in this list
E remove( int index ...