fossilesque@mander.xyzM to Science Memes@mander.xyzEnglish · 1 year agoExplain yourselves, comp sci.mander.xyzimagemessage-square46fedilinkarrow-up1504
arrow-up1504imageExplain yourselves, comp sci.mander.xyzfossilesque@mander.xyzM to Science Memes@mander.xyzEnglish · 1 year agomessage-square46fedilink
minus-squareDaPorkchop_@lemmy.mllinkfedilinkEnglisharrow-up1·1 year agoArrayList isn’t thread-safe, though…
minus-squareunalivejoy@lemm.eelinkfedilinkEnglisharrow-up1·1 year agoThread safe as in it raises an exception instead of breaking your list.
minus-squareDaPorkchop_@lemmy.mllinkfedilinkEnglisharrow-up1·1 year agoOnly if one thread modifies it while another one is iterating over it, if two threads try to modify the list at once there isn’t any kind of synchronization and it really could break your list.
minus-squareunalivejoy@lemm.eelinkfedilinkEnglisharrow-up1·1 year agoFor everything else, there’s Collections.synchronizedList(new ArrayList<>())
ArrayList isn’t thread-safe, though…
Thread safe as in it raises an exception instead of breaking your list.
Only if one thread modifies it while another one is iterating over it, if two threads try to modify the list at once there isn’t any kind of synchronization and it really could break your list.
For everything else, there’s
Collections.synchronizedList(new ArrayList<>())