Join Peggy Fisher for an in-depth discussion in this video Searching arrays, part of Up and Running with Java.
- View Offline
- Exercise Files
- Similar to sorting arrays,…there are many different ways to search arrays.…Let's start talking about a binary search.…A binary search requires the list of values…to already be sorted prior to searching.…The binary search starts by comparing…the key value you're searching for…with the middle value in your array.…If the value is greater than the middle value,…it repeats the process with the half of the array…that might still contain a match.…This process continues until either a match is found…or the array cannot be split any more.…
Let's look at an example on how this might work.…If this is my original sorted array…and I'm trying to find the value three,…the first time through it'll compare three to the middle.…It'll say, is three greater than or less than four.…In our case, it's less than,…so now it takes the beginning half of the array,…splits it again, but since there's only two items,…it's going to compare the three to both items…and find that there is a match.…Now let's take a look at a program…that uses a binary search.…
- Downloading and exploring NetBeans
- Understanding Java basics: data types, strings, arrays, and more
- Controlling flow with functions and loops
- Creating classes
- Sorting and searching arrays
- Manipulating files
- Handling errors
- Building GUIs
Skill Level Beginner
1. Getting Started
2. Java Basics
3. Flow of Control
4. Classes and Objects
5. Beyond the Basics
6. File Manipulation
7. Graphical User Interface Basics
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.