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,471
  • 17
  • 87
  • 173
mrbela
  • 4,156
  • 7
  • 42
  • 74

0 Answers0