Use the equals() method for comparing Strings, not the == operator.

The code should test the length of the String it is working on before assuming it is long enough for the substring method.