Summary List<E> Interface

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page        

Answer:

0, just as with an array.

Summary List<E> Interface

Here is a summary of the List<E> Interface. For the full interface see your Java documentation.

Method What it Does
boolean add(E elt)   
Appends element elt to the end of the list.
void add(int index, E elt)   
Inserts element elt at the specified index.
E get(int index)     
Returns a reference to the element at the specified index.
int indexOf(Object elem)    
Searches for the first occurence of elem,
testing for equality using the equals(Object) method.
E set(int index, E elt)   
Replaces the element at index with the specified element elt.
. . . many more . . . . . .

The methods are described in terms of the type reference to E that the list contains.

QUESTION 10:

Say that you have an ArrayList of references to String. What does the add() method look like?