English subtitles

← Mad Hatter - Intro to Java Programming

Get Embed Code
6 Languages

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

  1. So after the get number of characters method I'll add another method. From the
  2. fact sheet we can see that the index of method will help us. We want to return
  3. bookText.indexOf Mad hatter. Now we need to add that line to our test program,
  4. BookTester which prints out the actual value of
  5. Alice.firstOccurrenceOfMadHatter, looks like I capitalized it wrong. Alright,
  6. now let's see what this actually gives us. Huh, the actual value is negative
  7. one. That doesn't sound like a location. There shouldn't be a minus one
  8. character in the book. Let's look at the documentation. In my browser, I'll
  9. search for java 7 string and find the official documentation. And then I'm
  10. going to look for the index of method. Methods, index of, we're giving it a
  11. string. Alright, returns the index within this string of the first occurrence
  12. of the specified substring. That's what we were expecting. The returned index
  13. is the smallest value, k, for which this dot starts with stir, k. Not sure what
  14. that means yet, we can think about that later. If no such value of k exists.
  15. Then minus 1 is returned. Okay, so minus 1 means that there are no occurrences
  16. of Mad Hatter as we wrote it in the book. This might be surprising. The Mad
  17. Hatter is a famous charater. But it turns out, in the book, he's always just
  18. called the Hatter, not the Mad Hatter.