Skip to Main Content
Java For Dummies, 8th Edition
book

Java For Dummies, 8th Edition

by Barry Burd
April 2022
Beginner content levelBeginner
512 pages
11h 32m
English
For Dummies
Content preview from Java For Dummies, 8th Edition

Chapter 12

Using Collections and Streams (When Arrays Aren't Good Enough)

IN THIS CHAPTER

Bullet Facing the limitations of arrays

Bullet Dealing with a bunch of objects at once

Bullet Using Java's cool functional programming features

Bullet Developing code for multicore processors

Chapter 11 is about arrays. With an array, you can manage a bunch of things all at once. In a hotel management program, you can keep track of all the rooms. You can quickly find the number of people in a room or find a vacant room.

However, arrays don’t always fit the bill. In this chapter, you find out where arrays fall short and how collections can save the day.

Arrays Have Limitations

Imagine that you store customer names in some predetermined order. Your code contains an array, and the array has space for 100 names:

String[] name = new String[100];for (int i = 0; i < 100; i++) { name[i] = new String();}

All is well until, one day, customer number 101 shows up. As your program runs, you enter data for customer 101, hoping desperately that the array with 100 components can expand to fit your growing needs.

No such luck. Arrays ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Programming with Java For Dummies, 6th Edition

Beginning Programming with Java For Dummies, 6th Edition

Barry Burd
Learning Java, 5th Edition

Learning Java, 5th Edition

Marc Loy, Patrick Niemeyer, Daniel Leuck

Publisher Resources

ISBN: 9781119861645Purchase Link