6.1 Introduction

This chapter introduces data structures—collections of related data items. Array objects are data structures consisting of data items of the same type. Arrays make it convenient to process related groups of values. Arrays remain the same length once they’re created. We study data structures in depth in Chapters 1621.

After discussing how arrays are declared, created and initialized, we present practical examples that demonstrate common array manipulations. We introduce Java’s exception-handling mechanism and use it to allow a program to continue executing when it attempts to access an array element that does not exist. We introduce Java’s enhanced for statement, which allows a program to access the data in an array more easily ...

Get Java How To Program, Late Objects, 11th 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.