Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#pubctors) \| [Methods](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#inhmethods)

# AtomicInteger

` public class AtomicInteger `   
` ` ` extends https://developer.android.com/reference/java/lang/Number ` ` implements https://developer.android.com/reference/java/io/Serializable `

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) |||
| ↳ | [java.lang.Number](https://developer.android.com/reference/java/lang/Number) ||
|   | ↳ | java.util.concurrent.atomic.AtomicInteger |

<br />

*** ** * ** ***

An `int` value that may be updated atomically. See the `https://developer.android.com/reference/java/lang/invoke/VarHandle` specification for descriptions of the properties of atomic accesses. An `AtomicInteger` is used in applications such as atomically incremented counters, and cannot be used as a replacement for an `https://developer.android.com/reference/java/lang/Integer`. However, this class does extend `Number` to allow uniform access by tools and utilities that deal with numerically-based classes.

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#AtomicInteger()() ` Creates a new AtomicInteger with initial value `0`. |
| ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#AtomicInteger(int)(int initialValue) ` Creates a new AtomicInteger with the given initial value. |

| ### Public methods ||
|---|---|
| ` final int` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#accumulateAndGet(int,%20java.util.function.IntBinaryOperator)(int x, https://developer.android.com/reference/java/util/function/IntBinaryOperator accumulatorFunction) ` Atomically updates (with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndSet(java.lang.Object[])`) the current value with the results of applying the given function to the current and given values, returning the updated value. |
| ` final int` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#addAndGet(int)(int delta) ` Atomically adds the given value to the current value, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getAndAdd(java.lang.Object[])`. |
| ` final int` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#compareAndExchange(int,%20int)(int expectedValue, int newValue) ` Atomically sets the value to `newValue` if the current value, referred to as the *witness value* , `== expectedValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndExchange(java.lang.Object[])`. |
| ` final int` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#compareAndExchangeAcquire(int,%20int)(int expectedValue, int newValue) ` Atomically sets the value to `newValue` if the current value, referred to as the *witness value* , `== expectedValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndExchangeAcquire(java.lang.Object[])`. |
| ` final int` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#compareAndExchangeRelease(int,%20int)(int expectedValue, int newValue) ` Atomically sets the value to `newValue` if the current value, referred to as the *witness value* , `== expectedValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndExchangeRelease(java.lang.Object[])`. |
| ` final boolean` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#compareAndSet(int,%20int)(int expectedValue, int newValue) ` Atomically sets the value to `newValue` if the current value `== expectedValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndSet(java.lang.Object[])`. |
| ` final int` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#decrementAndGet()() ` Atomically decrements the current value, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getAndAdd(java.lang.Object[])`. |
| ` double` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#doubleValue()() ` Returns the current value of this `AtomicInteger` as a `double` after a widening primitive conversion, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getVolatile(java.lang.Object[])`. |
| ` float` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#floatValue()() ` Returns the current value of this `AtomicInteger` as a `float` after a widening primitive conversion, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getVolatile(java.lang.Object[])`. |
| ` final int` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#get()() ` Returns the current value, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getVolatile(java.lang.Object[])`. |
| ` final int` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#getAcquire()() ` Returns the current value, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getAcquire(java.lang.Object[])`. |
| ` final int` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#getAndAccumulate(int,%20java.util.function.IntBinaryOperator)(int x, https://developer.android.com/reference/java/util/function/IntBinaryOperator accumulatorFunction) ` Atomically updates (with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndSet(java.lang.Object[])`) the current value with the results of applying the given function to the current and given values, returning the previous value. |
| ` final int` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#getAndAdd(int)(int delta) ` Atomically adds the given value to the current value, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getAndAdd(java.lang.Object[])`. |
| ` final int` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#getAndDecrement()() ` Atomically decrements the current value, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getAndAdd(java.lang.Object[])`. |
| ` final int` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#getAndIncrement()() ` Atomically increments the current value, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getAndAdd(java.lang.Object[])`. |
| ` final int` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#getAndSet(int)(int newValue) ` Atomically sets the value to `newValue` and returns the old value, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getAndSet(java.lang.Object[])`. |
| ` final int` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#getAndUpdate(java.util.function.IntUnaryOperator)(https://developer.android.com/reference/java/util/function/IntUnaryOperator updateFunction) ` Atomically updates (with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndSet(java.lang.Object[])`) the current value with the results of applying the given function, returning the previous value. |
| ` final int` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#getOpaque()() ` Returns the current value, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getOpaque(java.lang.Object[])`. |
| ` final int` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#getPlain()() ` Returns the current value, with memory semantics of reading as if the variable was declared non-`volatile`. |
| ` final int` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#incrementAndGet()() ` Atomically increments the current value, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getAndAdd(java.lang.Object[])`. |
| ` int` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#intValue()() ` Returns the current value of this `AtomicInteger` as an `int`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getVolatile(java.lang.Object[])`. |
| ` final void` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#lazySet(int)(int newValue) ` Sets the value to `newValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#setRelease(java.lang.Object[])`. |
| ` long` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#longValue()() ` Returns the current value of this `AtomicInteger` as a `long` after a widening primitive conversion, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getVolatile(java.lang.Object[])`. |
| ` final void` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#set(int)(int newValue) ` Sets the value to `newValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#setVolatile(java.lang.Object[])`. |
| ` final void` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#setOpaque(int)(int newValue) ` Sets the value to `newValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#setOpaque(java.lang.Object[])`. |
| ` final void` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#setPlain(int)(int newValue) ` Sets the value to `newValue`, with memory semantics of setting as if the variable was declared non-`volatile` and non-`final`. |
| ` final void` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#setRelease(int)(int newValue) ` Sets the value to `newValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#setRelease(java.lang.Object[])`. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#toString()() ` <br /> |
| ` final int` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#updateAndGet(java.util.function.IntUnaryOperator)(https://developer.android.com/reference/java/util/function/IntUnaryOperator updateFunction) ` Atomically updates (with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndSet(java.lang.Object[])`) the current value with the results of applying the given function, returning the updated value. |
| ` final boolean` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#weakCompareAndSet(int,%20int)(int expectedValue, int newValue) ` *This method was deprecated in API level 33. This method has plain memory effects but the method name implies volatile memory effects (see methods such as `https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#compareAndExchange(int,%20int)` and `https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#compareAndSet(int,%20int)`). To avoid confusion over plain or volatile memory effects it is recommended that the method `https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#weakCompareAndSetPlain(int,%20int)` be used instead.* |
| ` final boolean` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#weakCompareAndSetAcquire(int,%20int)(int expectedValue, int newValue) ` Possibly atomically sets the value to `newValue` if the current value `== expectedValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#weakCompareAndSetAcquire(java.lang.Object[])`. |
| ` final boolean` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#weakCompareAndSetPlain(int,%20int)(int expectedValue, int newValue) ` Possibly atomically sets the value to `newValue` if the current value `== expectedValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#weakCompareAndSetPlain(java.lang.Object[])`. |
| ` final boolean` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#weakCompareAndSetRelease(int,%20int)(int expectedValue, int newValue) ` Possibly atomically sets the value to `newValue` if the current value `== expectedValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#weakCompareAndSetRelease(java.lang.Object[])`. |
| ` final boolean` | ` https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#weakCompareAndSetVolatile(int,%20int)(int expectedValue, int newValue) ` Possibly atomically sets the value to `newValue` if the current value `== expectedValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#weakCompareAndSet(java.lang.Object[])`. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Number ` ` byte` ` https://developer.android.com/reference/java/lang/Number#byteValue()() `

Returns the value of the specified number as a `byte`.
` abstract double` ` https://developer.android.com/reference/java/lang/Number#doubleValue()() `

Returns the value of the specified number as a `double`.
` abstract float` ` https://developer.android.com/reference/java/lang/Number#floatValue()() `

Returns the value of the specified number as a `float`.
` abstract int` ` https://developer.android.com/reference/java/lang/Number#intValue()() `

Returns the value of the specified number as an `int`.
` abstract long` ` https://developer.android.com/reference/java/lang/Number#longValue()() `

Returns the value of the specified number as a `long`.
` short` ` https://developer.android.com/reference/java/lang/Number#shortValue()() `

Returns the value of the specified number as a `short`.
From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Public constructors

### AtomicInteger

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public AtomicInteger ()
```

Creates a new AtomicInteger with initial value `0`.

<br />

### AtomicInteger

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public AtomicInteger (int initialValue)
```

Creates a new AtomicInteger with the given initial value.

<br />

| Parameters ||
|---|---|
| `initialValue` | `int`: the initial value <br /> |

## Public methods

### accumulateAndGet

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final int accumulateAndGet (int x, 
                IntBinaryOperator accumulatorFunction)
```

Atomically updates (with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndSet(java.lang.Object[])`) the current value with the results of applying the given function to the current and given values, returning the updated value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads. The function is applied with the current value as its first argument, and the given update as the second argument.

<br />

| Parameters ||
|---|---|
| `x` | `int`: the update value <br /> |
| `accumulatorFunction` | `IntBinaryOperator`: a side-effect-free function of two arguments <br /> |

| Returns ||
|---|---|
| `int` | the updated value <br /> |

### addAndGet

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final int addAndGet (int delta)
```

Atomically adds the given value to the current value, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getAndAdd(java.lang.Object[])`.

<br />

| Parameters ||
|---|---|
| `delta` | `int`: the value to add <br /> |

| Returns ||
|---|---|
| `int` | the updated value <br /> |

### compareAndExchange

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final int compareAndExchange (int expectedValue, 
                int newValue)
```

Atomically sets the value to `newValue` if the current value, referred to as the *witness value* , `== expectedValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndExchange(java.lang.Object[])`.

<br />

| Parameters ||
|---|---|
| `expectedValue` | `int`: the expected value <br /> |
| `newValue` | `int`: the new value <br /> |

| Returns ||
|---|---|
| `int` | the *witness value* , which will be the same as the expected value if successful <br /> |

### compareAndExchangeAcquire

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final int compareAndExchangeAcquire (int expectedValue, 
                int newValue)
```

Atomically sets the value to `newValue` if the current value, referred to as the *witness value* , `== expectedValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndExchangeAcquire(java.lang.Object[])`.

<br />

| Parameters ||
|---|---|
| `expectedValue` | `int`: the expected value <br /> |
| `newValue` | `int`: the new value <br /> |

| Returns ||
|---|---|
| `int` | the *witness value* , which will be the same as the expected value if successful <br /> |

### compareAndExchangeRelease

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final int compareAndExchangeRelease (int expectedValue, 
                int newValue)
```

Atomically sets the value to `newValue` if the current value, referred to as the *witness value* , `== expectedValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndExchangeRelease(java.lang.Object[])`.

<br />

| Parameters ||
|---|---|
| `expectedValue` | `int`: the expected value <br /> |
| `newValue` | `int`: the new value <br /> |

| Returns ||
|---|---|
| `int` | the *witness value* , which will be the same as the expected value if successful <br /> |

### compareAndSet

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final boolean compareAndSet (int expectedValue, 
                int newValue)
```

Atomically sets the value to `newValue` if the current value `== expectedValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndSet(java.lang.Object[])`.

<br />

| Parameters ||
|---|---|
| `expectedValue` | `int`: the expected value <br /> |
| `newValue` | `int`: the new value <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if successful. False return indicates that the actual value was not equal to the expected value. <br /> |

### decrementAndGet

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final int decrementAndGet ()
```

Atomically decrements the current value, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getAndAdd(java.lang.Object[])`.

Equivalent to `addAndGet(-1)`.

<br />

| Returns ||
|---|---|
| `int` | the updated value <br /> |

### doubleValue

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public double doubleValue ()
```

Returns the current value of this `AtomicInteger` as a `double` after a widening primitive conversion, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getVolatile(java.lang.Object[])`.

<br />

| Returns ||
|---|---|
| `double` | the numeric value represented by this object after conversion to type `double`. <br /> |

### floatValue

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public float floatValue ()
```

Returns the current value of this `AtomicInteger` as a `float` after a widening primitive conversion, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getVolatile(java.lang.Object[])`.

<br />

| Returns ||
|---|---|
| `float` | the numeric value represented by this object after conversion to type `float`. <br /> |

### get

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final int get ()
```

Returns the current value, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getVolatile(java.lang.Object[])`.

<br />

| Returns ||
|---|---|
| `int` | the current value <br /> |

### getAcquire

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final int getAcquire ()
```

Returns the current value, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getAcquire(java.lang.Object[])`.

<br />

| Returns ||
|---|---|
| `int` | the value <br /> |

### getAndAccumulate

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final int getAndAccumulate (int x, 
                IntBinaryOperator accumulatorFunction)
```

Atomically updates (with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndSet(java.lang.Object[])`) the current value with the results of applying the given function to the current and given values, returning the previous value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads. The function is applied with the current value as its first argument, and the given update as the second argument.

<br />

| Parameters ||
|---|---|
| `x` | `int`: the update value <br /> |
| `accumulatorFunction` | `IntBinaryOperator`: a side-effect-free function of two arguments <br /> |

| Returns ||
|---|---|
| `int` | the previous value <br /> |

### getAndAdd

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final int getAndAdd (int delta)
```

Atomically adds the given value to the current value, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getAndAdd(java.lang.Object[])`.

<br />

| Parameters ||
|---|---|
| `delta` | `int`: the value to add <br /> |

| Returns ||
|---|---|
| `int` | the previous value <br /> |

### getAndDecrement

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final int getAndDecrement ()
```

Atomically decrements the current value, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getAndAdd(java.lang.Object[])`.

Equivalent to `getAndAdd(-1)`.

<br />

| Returns ||
|---|---|
| `int` | the previous value <br /> |

### getAndIncrement

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final int getAndIncrement ()
```

Atomically increments the current value, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getAndAdd(java.lang.Object[])`.

Equivalent to `getAndAdd(1)`.

<br />

| Returns ||
|---|---|
| `int` | the previous value <br /> |

### getAndSet

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final int getAndSet (int newValue)
```

Atomically sets the value to `newValue` and returns the old value, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getAndSet(java.lang.Object[])`.

<br />

| Parameters ||
|---|---|
| `newValue` | `int`: the new value <br /> |

| Returns ||
|---|---|
| `int` | the previous value <br /> |

### getAndUpdate

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final int getAndUpdate (IntUnaryOperator updateFunction)
```

Atomically updates (with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndSet(java.lang.Object[])`) the current value with the results of applying the given function, returning the previous value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads.

<br />

| Parameters ||
|---|---|
| `updateFunction` | `IntUnaryOperator`: a side-effect-free function <br /> |

| Returns ||
|---|---|
| `int` | the previous value <br /> |

### getOpaque

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final int getOpaque ()
```

Returns the current value, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getOpaque(java.lang.Object[])`.

<br />

| Returns ||
|---|---|
| `int` | the value <br /> |

### getPlain

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final int getPlain ()
```

Returns the current value, with memory semantics of reading as if the variable was declared non-`volatile`.

<br />

| Returns ||
|---|---|
| `int` | the value <br /> |

### incrementAndGet

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final int incrementAndGet ()
```

Atomically increments the current value, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getAndAdd(java.lang.Object[])`.

Equivalent to `addAndGet(1)`.

<br />

| Returns ||
|---|---|
| `int` | the updated value <br /> |

### intValue

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int intValue ()
```

Returns the current value of this `AtomicInteger` as an `int`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getVolatile(java.lang.Object[])`. Equivalent to `https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#get()`.

<br />

| Returns ||
|---|---|
| `int` | the numeric value represented by this object after conversion to type `int`. <br /> |

### lazySet

Added in [API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final void lazySet (int newValue)
```

Sets the value to `newValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#setRelease(java.lang.Object[])`.

<br />

| Parameters ||
|---|---|
| `newValue` | `int`: the new value <br /> |

### longValue

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public long longValue ()
```

Returns the current value of this `AtomicInteger` as a `long` after a widening primitive conversion, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#getVolatile(java.lang.Object[])`.

<br />

| Returns ||
|---|---|
| `long` | the numeric value represented by this object after conversion to type `long`. <br /> |

### set

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final void set (int newValue)
```

Sets the value to `newValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#setVolatile(java.lang.Object[])`.

<br />

| Parameters ||
|---|---|
| `newValue` | `int`: the new value <br /> |

### setOpaque

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final void setOpaque (int newValue)
```

Sets the value to `newValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#setOpaque(java.lang.Object[])`.

<br />

| Parameters ||
|---|---|
| `newValue` | `int`: the new value <br /> |

### setPlain

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final void setPlain (int newValue)
```

Sets the value to `newValue`, with memory semantics of setting as if the variable was declared non-`volatile` and non-`final`.

<br />

| Parameters ||
|---|---|
| `newValue` | `int`: the new value <br /> |

### setRelease

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final void setRelease (int newValue)
```

Sets the value to `newValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#setRelease(java.lang.Object[])`.

<br />

| Parameters ||
|---|---|
| `newValue` | `int`: the new value <br /> |

### toString

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toString ()
```

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the String representation of the current value <br /> |

### updateAndGet

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final int updateAndGet (IntUnaryOperator updateFunction)
```

Atomically updates (with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndSet(java.lang.Object[])`) the current value with the results of applying the given function, returning the updated value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads.

<br />

| Parameters ||
|---|---|
| `updateFunction` | `IntUnaryOperator`: a side-effect-free function <br /> |

| Returns ||
|---|---|
| `int` | the updated value <br /> |

### weakCompareAndSet

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final boolean weakCompareAndSet (int expectedValue, 
                int newValue)
```

<br />

**This method was deprecated in API level 33.**   

This method has plain memory effects but the method name implies volatile memory effects (see methods such as `https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#compareAndExchange(int,%20int)` and `https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#compareAndSet(int,%20int)`). To avoid confusion over plain or volatile memory effects it is recommended that the method `https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#weakCompareAndSetPlain(int,%20int)` be used instead.

Possibly atomically sets the value to `newValue` if the current value `== expectedValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#weakCompareAndSetPlain(java.lang.Object[])`.

<br />

| Parameters ||
|---|---|
| `expectedValue` | `int`: the expected value <br /> |
| `newValue` | `int`: the new value <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if successful <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger#weakCompareAndSetPlain(int,%20int)`

### weakCompareAndSetAcquire

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final boolean weakCompareAndSetAcquire (int expectedValue, 
                int newValue)
```

Possibly atomically sets the value to `newValue` if the current value `== expectedValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#weakCompareAndSetAcquire(java.lang.Object[])`.

<br />

| Parameters ||
|---|---|
| `expectedValue` | `int`: the expected value <br /> |
| `newValue` | `int`: the new value <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if successful <br /> |

### weakCompareAndSetPlain

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final boolean weakCompareAndSetPlain (int expectedValue, 
                int newValue)
```

Possibly atomically sets the value to `newValue` if the current value `== expectedValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#weakCompareAndSetPlain(java.lang.Object[])`.

<br />

| Parameters ||
|---|---|
| `expectedValue` | `int`: the expected value <br /> |
| `newValue` | `int`: the new value <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if successful <br /> |

### weakCompareAndSetRelease

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final boolean weakCompareAndSetRelease (int expectedValue, 
                int newValue)
```

Possibly atomically sets the value to `newValue` if the current value `== expectedValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#weakCompareAndSetRelease(java.lang.Object[])`.

<br />

| Parameters ||
|---|---|
| `expectedValue` | `int`: the expected value <br /> |
| `newValue` | `int`: the new value <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if successful <br /> |

### weakCompareAndSetVolatile

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final boolean weakCompareAndSetVolatile (int expectedValue, 
                int newValue)
```

Possibly atomically sets the value to `newValue` if the current value `== expectedValue`, with memory effects as specified by `https://developer.android.com/reference/java/lang/invoke/VarHandle#weakCompareAndSet(java.lang.Object[])`.

<br />

| Parameters ||
|---|---|
| `expectedValue` | `int`: the expected value <br /> |
| `newValue` | `int`: the new value <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if successful <br /> |