8.6 Searching and Sorting Arrays
Arrays are great instruments for storing a large number of related values. As seen earlier in this chapter, we can use arrays to store daily temperatures, CD titles, telephone bills, quiz grades, and other sets of related values. Once the data is stored in an array, we will want to manipulate that data. A very common operation is searching an array for a specific value.
8.6.1 Sequential Search of an Unsorted Array
Let’s assume we manage a movie theater. We give each customer a frequent moviegoer card with a unique member ID. We have decided to pick four member IDs at random and give those members a free gift the next time they visit the theater. So we set up a MovieWinners class with two array instance variables: ...
Get Java Illuminated, 5th 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.