Differences between concurrent and synchronized collections in Java?

Viewed 3156

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?

0 Answers
Related