AtomicIntegerArray

Comprehensive guide to working with AtomicIntegerArray

If you are interviewing, consider buying our number#1 course for Java Multithreading Interviews.

Overview

The class AtomicIntegerArray represents an array of type int (integers) that can be updated atomically. An instance of the AtomicIntegerArray can be constructed either by passing an existing array of int or by specifying the desired size to the constructors of AtomicIntegerArray. The int data type is a 32-bit signed two’s complement integer, which has a minimum value of -231 and a maximum value of 231-1. In Java SE 8 and later, the Integer class can be used to represent an unsigned 32-bit integer, which has a minimum value of 0 and a maximum value of 232-1.

One notable difference between an ordinary array of int-s and an AtomicIntegerArray is that the latter provides volatile access semantics for its array elements, which isn’t supported for ordinary arrays.

Example

The code widget below demonstrates constructing an instance of AtomicIntegerArray and the various operations possible on it. Comments have been added to explain the various operations.

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy