The base cases are:
1. equals( "", "" ) = true 2. equals( "", X ) = false if X is not the empty string 3. equals( X, "" ) = false if X is not the empty string 4. equals( x+X, y+Y ) = false if x != y
These are base cases because the result can be computed immediately.
Of course there is an equals()
method that is part of the
class String
.
Let us forget this and write our own method.
This should be merely a matter of translation:
To detect an empty string, check if the length is zero.
Remember that an empty string is a string that contains no characters.
The value null
is something different.
The method call strA.substring(1)
returns the substring that consists
of character 1 and all characters that follow it in strA
.
Those blanks are made for filling.