r/java • u/loicmathieu • Jan 22 '26
Java 26: what’s new?
https://www.loicmathieu.fr/wordpress/informatique/java-26-whats-new/What's new in Java 26 for us, developers
(Bot in English and French)
163
Upvotes
View all comments
Show parent comment
15
u/vowelqueue Jan 22 '26
Using the iterator can be tricky because you don’t know if the size of the collection has changed between when you call size() and when you start iterating, or if the collection supports structural modification during iteration.
In contrast, you can rely on toArray() to get a coherent snapshot of the collection that does not change in size.
Also array copy performs well