First I must insist that you should not do this. It does not make sense to pass up a programming error. I talk a lot about it and you can start reading in that answer .
Second, it is not easy to help in this way because we do not know what to do when the error occurs. You can even try to use your imagination, but it's still complicated because any solution might be wrong.
Finally, if there is really any reason to continue working despite having an invalid index, do not let the index be accessed, that is, it prevents the error.
You should only catch exceptions that are unavoidable for one reason or another. Exceptions should not be used for normal flow control.
If an exception occurs and should not occur, it is a programming error and it should be fixed. The most you should do in this case is let go back to the beginning and there catch an exception, write in a log that the error occurred for verification. It has several techniques for writing in the logo, and can even alert the developer immediately in circumstances where external communication is working.
If the exception occurs and you know it is normal, you can work around the problem without a race condition , then let it occur, check the situation before and avoid the error.
I'll try a solution here that I think is what you want:
for (String f : filename) {
String temporario[] = f.split("_");
if (temporario.length > 1) {
Date data = new Date(format.parse(temporario[1]).getTime());
if (m.containsKey(temporario[0])) {
if (m.get(temporario[0]).before(data)) {
m.put(temporario[0], data);
}
} else {
m.put(temporario[0], data);
}
}
}
Note that this solution does not seem robust to me. It will probably produce unwanted results if something is not in order. But only you know whether this is acceptable or not.