简体   繁体   中英

Is there concurrent mutable Array(or any other indexed random access) in Scala/Java?

I want to store count of integers in the corresponding indexes. Be able to update counts in parallel. I've found java.util.concurrent.atomic.AtomicIntegerArray but it's impossible to get underlying array through API( I want to map over this array in the end)

Since the AtomicIntegerArray supports length method we can iterate over it as shown below. (using scala)

(0 to atomicIntegerArray.length()-1)
   .map(atomicIntegerArray.get)
   .map( x =>  /*your map logic*/ )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM