I'd like to remove all elements that have null values from the ArrayList or String array in Java For me,
for (Tourist t : tourists) {
if (t != null) {
t.setId(idForm);
}
}
I tried turning around the loop like this, but it didn't work out as I wanted. Is there a good way?
arraylist for-loop java loops performance
tourists.removeAll(Collections.singleton(null));
Do it like this.
© 2024 OneMinuteCode. All rights reserved.