YouTube

Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← Array Algorithms Find All Matches - Intro to Java Programming

Get Embed Code
5 Languages

Showing Revision 4 created 05/25/2016 by Udacity Robot.

  1. You've seen how to find the first match now we want to find them all. In our
  2. picture example we just want to collect all of the portraits. This one, and
  3. this one. Now if we want to collect them we need to put them somewhere. And you
  4. just learned how to collect stuff, namely with an ArrayList. So we have two
  5. ArrayLists, the one that contains the elements that we inspect and the one in
  6. which we will collect our matches. Now for each element in the original
  7. ArrayList we check if it's a match and if so we add the matching element to the
  8. ArrayList matches. When this loop is complete matches contains all matches.
  9. Like I said this one is actually simpler because we don't need to keep track of
  10. whether we have found the first one we don't need to stop after we found the
  11. first one. Go ahead and implement it in Java.