CodingBat warm up: conditionally prepending "not" to a string
It should be obvious which strategy is better. Suppose you are given a very long string. Do you really want to search the entire string for "not", then realize that the match is irrelevant because it doesn't occur at the beginning?  Or would you rather just examine the first three characters of the string?

Of course, the most straightforward solution uses .startsWith():

public String notString(String str) {
    return str.startsWith("not") ? str : "not " + str;
}


I don't know why they gave a hint to use .equals(). It's also a bit unclear how a string like "notary" should be handled. Treat these tutorial-challenge sites with some suspicion.