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:

It is more efficient to increase capacity by a large amount a few times rather than to increase capacity by one every time a new element is added.

List<E> Interface

Lists of things are common in the real world and in programming. People make lists of things they need to buy and lists of things they need to do. An examination often consists of a list of questions. A text editor program might keep lines of text in a list.

ArrayList implements the List<E> interface. The List<E> interface captures the idea of a list without saying how the idea is implemented. ArrayList is just one implementation of the idea. Recall that an interface consists of constants and method declarations. A class that implements an interface must implement each of the methods listed in the interface. There are no constants in List<E>, but there are many methods.

A list is an ordered collection of elements. Duplicate elements are allowed in an ArrayList (and in most other implementations of list). Items in a list can be accessed by their index, as with an array. There are methods to add elements, get elements, remove elements, and search for elements (and many other methods).

QUESTION 9:

(Thought Question: ) What is the first value of a list index?