2

In Java there are

  1. concurrent collections (e.g. java.util.concurrent.CopyOnWriteArrayList)

  2. synchronized collections (e.g. Collections.synchronizedList(List<T> list))

My insights so far:

  • both types are thread safe regarding invoking their operations (add(), get() and so on)
  • BUT: If you iterate over a Collection from type 2) it isn't thread safe at all (compare this answer).Whereas iterating over a Collection of type 1) is thread safe.

Are there any other differences? And why has Java both types of collections? Wouldn't it be clearer to only have one type?

halfer
  • 19,824
  • 17
  • 99
  • 186
mrbela
  • 4,477
  • 9
  • 44
  • 79

0 Answers0