English subtitles

← strings - Intro to Java Programming

Get Embed Code
6 Languages

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

  1. Here are the answers that I got. The length method returns the number of
  2. individual characters in the string. There were 7. The substring method
  3. extracts a substring that sits inside the bigger string. In our case, it
  4. extracted this string. Whenever you want to extract substrings, you have to
  5. understand how the positions in a string are numbered. In Java the initial
  6. position is 0, that may sound strange but it's actually pretty useful, and then
  7. it goes from there. The string has length 7 and the position's in it are 0, 1,
  8. 2, 3, 4, 5, 6. That's 7 position's. Now in the substring here you see this 3
  9. here. That is the position of the first character that we want to include in
  10. the substring. The seven here is the first position that we don't want to have
  11. anymore. We don't want position seven. In fact, there is no position seven. We
  12. want the ones from three to six. That sounds a bit odd to most people when they
  13. see it the first time. But there is an advantage. When you subtract these two
  14. numbers, 7 minus 3, that's 4, and that's the length of the substring that
  15. you're extracting. The next method here, the indexOf method finds the position
  16. of a given character. So, over here I want to know where does the C occur for
  17. the first time. And it will go through and say, that's at position three. And
  18. finally, you already seen this plus operator in lesson two. It takes two
  19. strings and glues them together or as we like to say in programming is, it
  20. concatenates them. So, here is the concatenation of Hello and Udacity, notice
  21. there's no space in between because there was no space in either this or that
  22. string. If you wanted a space, you'd have to add a space. Strings are really
  23. useful when you work with text. Sarah has a couple of nifty exercises prepared
  24. for you when you get to work with a rather long text and take it apart. And put
  25. pieces back together by using some of the string methods that you've seen here.
  26. Enjoy.