For example, String letters = "fourgooddogsswam";
Is there a way I can scan the string from left to right 4 characters at a time so that I can set(four ourg urgo rgoo good oodd oddo ddog dogs ogss gssw sswa swam) into a string array? I tried using loops but I'm having difficulties getting it to work properly.
Thanks!
public static String[] findWordsOfLength(String letters, int wordSize) {
if(letters == null) {
return null;
}
int size = letters.length();
int wordMax = size - wordSize + 1;
if(size < wordMax || wordMax <= 0) {
return new String[0];
}
int j = 0;
String[] result = new String[wordMax];
for (int i = 0; i < wordMax; i++) {
result[j ++] = letters.substring(i, i + wordSize);
}
return result;
}