• Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayList  RSS feed

 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"You are usually better off using the collections defined in the java.util.concurrent package
instead of the synchronization wrappers. In particular, the ConcurrentHashMap map has been
carefully implemented so that multiple threads can access it without blocking each other,
provided they access different buckets. One exception is an array list that is frequently
mutated. In that case, a synchronized ArrayList can outperform a CopyOnWriteArrayList.
"

Core Java Volume 1 (8th Edition) P.773.

Why?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess because each time you add something to a CopyOnWriteArrayList, it will make a copy of the list (note the name of the class). See also its API documentation.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!