I am trying to execute a java method solve(String s) which takes the string and returns the biggest number present in the string. (The string contains letters and numbers). Whenever I try to run the code it throws an error - java.lang.IndexOutOfBoundsException: Index: 11, Size: 11 This is my code:
public ArrayList<Integer> getIntArray(ArrayList<String> stringArray) {
ArrayList<Integer> result = new ArrayList<Integer>();
for(String stringVal : stringArray) {
result.add(Integer.parseInt(stringVal));
}
return result;
}
public int solve(String s) {
StringBuilder str = new StringBuilder(s);
ArrayList<String> arr = new ArrayList<String>();
String[] strArr = s.split("");
for(int i = 0; i < strArr.length; i++) {
arr.add(strArr[i]);
}
for(int i = 0; i < strArr.length; i++) {
if(!Character.isLetter(i)) {
arr.remove(i);
}
}
ArrayList<Integer> intArr = new ArrayList<Integer>();
intArr = getIntArray(arr);
return Collections.max(intArr);
Thanks. Any help will be appreciated.