Chapter 2

Using Arrays

In This Chapter

arrow Working with basic one-dimensional arrays

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

arrow Using for loops with arrays

arrow Working with two-dimensional arrays

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

Get Java All-in-One For Dummies, 4th 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.