Chapter 2

Using Arrays

IN THIS CHAPTER

check Working with basic one-dimensional arrays

check Using array initializers to set the initial values of an array

check Using for loops with arrays

check Working with two-dimensional arrays

check Working with the Arrays class

I could use a raise… .

Oh, arrays. Sorry.

Arrays are an important aspect of any programming language, and Java is no exception. In this chapter, you discover just about everything you need to know about using arrays. I cover run-of-the-mill one-dimensional arrays; multidimensional arrays; and two classes that are used to work with arrays, named Array and Arrays.

Understanding Arrays

An array is a set of variables that is referenced by using a single variable name combined with an index number. Each item of an array is called an element. All the elements in an array must be of the same type. Thus the array itself has a type that specifies what kind of elements it can contain. An int array can contain int values, for example, and a String array can ...

Get Java All-in-One For Dummies, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.