5 - Substring

Get an introduction to or review of substring operations in Java programming.

Code HuntJava
1.0x

5 - Substring

Created 2 years ago

Duration 0:02:57
lesson view count 8
Get an introduction to or review of substring operations in Java programming.
Select the file type you wish to download
Slide Content
Tags: Code Hunt Java
  1. Working With substring()

    Slide 2 - Working With substring()

  2. The substring() Method

    Slide 3 - The substring() Method

    • The substring() method allows us to pull out part of a larger String.
    • We can get a chunk from the middle:
    • or from the end:
  3. substring() with one argument

    Slide 4 - substring() with one argument

    • To get a chunk from the end of the String, we use:
    • <target>.substring(start)
    • where start is the index of the first character we want in the substring.
    • Remember that we start counting at 0.
    • "substring".substring(3)
    • "racecar".substring(4)
    • "banana".substring(0)
    • String str = "devour";
    • str.substring(str.length() – 3)
  4. substring() with two arguments

    Slide 5 - substring() with two arguments

    • To get a chunk from the middle of the String, we use:
    • <target>.substring(start, end)
    • where start is the index of the first character we want in the substring, and end is the index of the first character we DON’T want in the substring.
    • The character at index end will not be in the substring.
    • "substring".substring(0, 3)
    • "racecar".substring(1, 4)
    • "banana".substring(2, 6)
    • String str = "devour";
    • str.substring(1, str.length() – 2)
  5. Check your understanding

    Slide 6 - Check your understanding

  6. Check your understanding

    Slide 7 - Check your understanding

  7. Practice #1

    Slide 8 - Practice #1

  8. practice #2

    Slide 9 - practice #2

  9. Practice #3

    Slide 10 - Practice #3

  10. Practice #4

    Slide 11 - Practice #4

  11. Practice #5

    Slide 12 - Practice #5

  12. Practice #6

    Slide 13 - Practice #6

  13. Practice #7

    Slide 14 - Practice #7

  14. Practice #8

    Slide 15 - Practice #8

  15. Practice #9

    Slide 16 - Practice #9