2.10 Implementing String Algorithms

0 阅读1分钟

1. Exam Points

  • Algorithms to manipulate strings
    • find if one or more substrings have a particular property
    • determine the number of substrings that meet specific criteria
    • create a new string with the characters reversed
  • Note:
    • Use specific example values when necessary.
    • Index of a string starts with 0 and ends with length-1
    • Valid index: 0 to length
    • An index of -1 or > length will cause errors (IndexOutOfBoundsException)
    • Get 1 characters: substring(index, index + 1)
    • Get n characters: substring(index, index + n)

2. Knowledge Points

(1) Implementing String Algorithms

  • Pay attention when manipulating strings:
    • get EF from string ABEF
      • str.substring(2,4)
    • valid index in string ABEF
      • 0 to 4 (0 to length)
    • invalid index: index<0 or index>length
    • get one character
      • str.substring(i, i+1)
    • get n characters
      • str.substring(i, i+n)
  • There are standard string algorithms to:
      1. find if one or more substrings have a particular property
      • Ex. count consecutive pairs in a string : abbcdddeff image.png
      1. determine the number of substrings that meet specific criteria
      • Ex. determine the number of ABCs in string ABCdeABCffABC image.png
      1. create a new string with the characters reversed
      • Ex. print the reversed string of ABCD, that is DCBA image.png

3. Exercises