Arrays

This chapter introduces arrays, a common multi-dimensional data structure used to store data of the same type. (Note that a class is a "data type" in this sense.) Arrays have some number of dimensions and a number of elements in each dimension. These are established when the array is created. The range of the array's index in each dimension goes from zero to the number of that dimension's elements minus one. A for loop is commonly used to initialize, manipulate, and access the values in an array. Here, we treat one-dimensional arrays, sometimes called vectors.

1. Arrays

Most real-world programs handle vast amounts of data. Fortunately, data usually can be organized and processed systematically. Arrays or similar structures are almost always used for this. When data is organized into arrays and processed in loops, a relatively small program can handle a vast amount of data. This chapter discusses arrays and shows examples of how they work.

Chapter Topics:

      • The idea of arrays
      • Array declaration
      • Array declaration and construction
      • Using arrays
      • Automatic bounds checking
      • Initializer lists

Question 1:

Say that you are writing a program that reads in 100 numbers. Would you like to declare 100 variables and write 100 input statements?


Source: Bradley Kjell, http://programmedlessons.org/Java9/chap60/ch60_01.html
Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 License.