I have an array list of strings and I would like to remove strings which are below a certain length. I was thinking about this method:
for (int i = 0; i < result.size(); i++) {
if (result.get(i).split("\\s").length != maxLength) {
System.out.println(result.get(i));
result.remove(i);
}
}
But it is only removing few entries because when it removes one then it shifts the next one in the place of removed one. What is the other way to do that
Never remove from an ArrayList in that way. Use an Iterator instead: