To become familiar with using arrays and array lists
To learn about wrapper classes, auto-boxing, and the enhanced
To study common array algorithms
To learn how to use two-dimensional arrays
To understand when to choose array lists and arrays in your programs
To implement partially filled arrays
T To understand the concept of regression testing
In order to process large quantities of data, you need to have a mechanism for collecting values. In Java, arrays and array lists serve this purpose. In this chapter, you will learn how to construct arrays and array lists, fill them with values, and access the stored values. We introduce the enhanced
for loop, a convenient statement for processing all elements of a collection. You will see how to use the enhanced
for loop, as well as ordinary loops, to implement common array algorithms. The chapter concludes with a discussion of two-dimensional arrays, which are useful for handling rows and columns of data.
In many programs, you need to manipulate collections of related values. It would be impractical to use a sequence of variables such as
value1, value2, value3, . . ., and so on. The array construct provides a better way of storing a collection of values.
An array is a sequence of values of the same type. The values that are stored in an array are called its "elements". For example, here is how you construct an array of 10 floating-point numbers:
An array is a sequence ...