Java Array List

Characteristics of Array Lists
  • duplicates are allowed
  • positional order is significant (lists are sequences)
  • slow when you add to the front of the list.
The Java API contains many methods that will work on Array Lists

This sample code show how words are added to an ArrayList.

Sample Code

Things to Notice:
  • the items are place in the list in the order that they were added 
  • tired of typing System.out every time you need to print something? Notice how you can shorten you code.
  • when ArrayList l is printed, the data in the list is printed.  It is printing the ArrayList based on the toString() method in the ArrayList class.
  • notice there is a new type of for loop -- it is referred to as a "for each" loop; as in  "for each item in the list"
  • the <String> indicates the data type that will be stored in the ArrayList