Fixed-length Array

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        
String[] list = new String[5];

Answer:

The array object has five cells.

Fixed-length Array

Once an array object has been constructed, the number of cells will not change. It must be constructed with a length that will accommodate all expected data. Unfortunately, sometimes this length is hard to determine in advance. Depending on the data, the program might need differents sizes each time it is run. It would be nice if there were a type of array that allowed you to keep adding data regardless of its original length.

QUESTION 2:

Say that an array has been declared and has been completely filled with information:

String[] list = new String[3];
list[0] = "ant" ;
list[1] = "bat" ;
list[2] = "cat" ;

After running for a while, the program needs to add information to the array. Will the following statement make the array larger?

list = new String[5];