| Code with Finding: |
class StrBuilder {
/**
* Checks whether this builder starts with the specified string.
* <p>
* Note that this method handles null input quietly, unlike String.
*
* @param str the string to search for, null returns false
* @return true if the builder starts with the string
*/
public boolean startsWith(String str) {
if (str == null) {
return false;
}
int len = str.length();
if (len == 0) {
return true;
}
if (len > size) {
return false;
}
for (int i = 0; i < len; i++) {
if (buffer[i] != str.charAt(i)) {
return false;
}
}
return true;
}
}
|