O'Reilly logo

Big Java, 4th Edition by Cay Horstmann

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7. Arrays and Array Lists

CHAPTER GOALS

  • To become familiar with using arrays and array lists

  • To learn about wrapper classes, auto-boxing, and the enhanced for loop

  • 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.

Arrays

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:

new double[10]

Note

An array is a sequence ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required