|
Previously, we wrote a String class that addressed instances of two of
those categories:
| Problem |
Solution using a String class |
|
The error of accessing characters outside a string
|
Make the String's data private and only allow
access to the characters of the string via a method that does
range-checking.
|
|
The inefficient acquisition of a string's length
|
Store the length of the string as an additional piece of data in the
String class. Update that field every time the contents
of the string is altered.
|
|