Nothing fancy. Just loop, and ignore exceptions:
List<Integer> list = new ArrayList<>();
for (String num : "1 23 35 5d 8 0 f".split(" ")) {
try {
list.add(Integer.parseInt(num));
} catch (NumberFormatException e) {}
}
*Edit*: If invalid integers are common, you will get better performance using a manual check of the digits of each part:
List<Integer> list = new ArrayList<>();
outer:
for (String num : "1 23 35 5d 8 0 f".split(" ")) {
for (int i = 0; i < num.length(); i++) {
char c = num.charAt(i);
if (!((c >= '0' && c <= '9') || c == '-' || c == '+')) continue outer;
}
try {
list.add(Integer.parseInt(num));
} catch (NumberFormatException e) {}
}
This still has the try-catch in order to reject out of range integers or any that have minus/plus signs in inappropriate places, but you can remove that if you know those don't occur in your data, or if you'd prefer to throw the exception for those cases.