I am trying to find the largest number in a string array that includes letters. How do I remove elements that aren't numeric from the array, whilst its in a For loop?
String word = "abcd:1234";
String[] testArray = test2.split("");
int max = Integer.MIN_VALUE, maxIndex = 0;
int secondMax = Integer.MIN_VALUE;
for (int i = 0; i < testArray.length; i++) {
if (Integer.parseInt(testArray[i]) > max) {
secondMax = max;
max = Integer.parseInt(testArray[i]);
maxIndex = i;
}else if(secondMax < Integer.parseInt(testArray[i])){
secondMax = Integer.parseInt(testArray[i]);
}
}
System.out.println(secondMax);