|
|
|
|
|
by newgame
4024 days ago
|
|
What about iterating from the end of the list in this particular case. This way you don't need a temporary list for (int i = names.size()-1; i >= 0; i--) {
String name = names.get(i);
if (name.startsWith("B")) names.remove(i);
}
Admittedly, needing to use an explicit index counter is not as nice (and more prone to errors) as using the other for syntax. But one could imagine a language with e.g. macros that made the backwards-looping syntax more intuitive (I assume a single-threaded situation and an ArrayList).Your general point still stands though. |
|