This method is supposed to get the number of occurrences of a certain pattern and return the int value. I keep getting this error
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
Code
public int getCount(String pattern){
int occerenceOfPattern = 0;
for (int i = 0; i <= strand.length(); i++) {
if (strand.substring(i, i + pattern.length()) == pattern) {
occerenceOfPattern++;
}
}
return occerenceOfPattern;
}