# AtomicLong

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/AtomicLong#pubctors)\|[Methods](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicLong#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicLong#inhmethods)  

# AtomicLong

`
public


class
AtomicLong
`  
`


``

extends `[Number](https://developer.android.com/reference/java/lang/Number)`


``


implements

`[Serializable](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.AtomicLong |

<br />

*** ** * ** ***

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

## Summary

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

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

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Number](https://developer.android.com/reference/java/lang/Number)` ` |--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------| | ` byte`            | ` `[byteValue](https://developer.android.com/reference/java/lang/Number#byteValue())`() ` Returns the value of the specified number as a`byte`.       | | ` abstract double` | ` `[doubleValue](https://developer.android.com/reference/java/lang/Number#doubleValue())`() ` Returns the value of the specified number as a`double`. | | ` abstract float`  | ` `[floatValue](https://developer.android.com/reference/java/lang/Number#floatValue())`() ` Returns the value of the specified number as a`float`.    | | ` abstract int`    | ` `[intValue](https://developer.android.com/reference/java/lang/Number#intValue())`() ` Returns the value of the specified number as an`int`.         | | ` abstract long`   | ` `[longValue](https://developer.android.com/reference/java/lang/Number#longValue())`() ` Returns the value of the specified number as a`long`.       | | ` short`           | ` `[shortValue](https://developer.android.com/reference/java/lang/Number#shortValue())`() ` Returns the value of the specified number as a`short`.    | ||
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](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 `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](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`                                                                  | ` `[wait](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`                                                                  | ` `[wait](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

### AtomicLong

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

```
public AtomicLong ()
```

Creates a new AtomicLong with initial value`0`.

<br />

### AtomicLong

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

```
public AtomicLong (long initialValue)
```

Creates a new AtomicLong with the given initial value.

<br />

|                    Parameters                    ||
|----------------|----------------------------------|
| `initialValue` | `long`: 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 long accumulateAndGet (long x, 
                LongBinaryOperator accumulatorFunction)
```

Atomically updates (with memory effects as specified by[VarHandle.compareAndSet(Object)](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`                   | `long`: the update value <br />                                           |
| `accumulatorFunction` | `LongBinaryOperator`: a side-effect-free function of two arguments <br /> |

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

### addAndGet

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

```
public final long addAndGet (long delta)
```

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

<br />

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

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

### compareAndExchange

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

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

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

<br />

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

|                                            Returns                                             ||
|--------|----------------------------------------------------------------------------------------|
| `long` | 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 long compareAndExchangeAcquire (long expectedValue, 
                long newValue)
```

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

<br />

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

|                                            Returns                                             ||
|--------|----------------------------------------------------------------------------------------|
| `long` | 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 long compareAndExchangeRelease (long expectedValue, 
                long newValue)
```

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

<br />

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

|                                            Returns                                             ||
|--------|----------------------------------------------------------------------------------------|
| `long` | 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 (long expectedValue, 
                long newValue)
```

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

<br />

|                     Parameters                     ||
|-----------------|-----------------------------------|
| `expectedValue` | `long`: the expected value <br /> |
| `newValue`      | `long`: 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 long decrementAndGet ()
```

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

Equivalent to`addAndGet(-1)`.

<br />

|             Returns              ||
|--------|--------------------------|
| `long` | 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`AtomicLong`as a`double`after a widening primitive conversion, with memory effects as specified by[VarHandle.getVolatile](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`AtomicLong`as a`float`after a widening primitive conversion, with memory effects as specified by[VarHandle.getVolatile](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 long get ()
```

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

<br />

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

### getAcquire

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

```
public final long getAcquire ()
```

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

<br />

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

### getAndAccumulate

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

```
public final long getAndAccumulate (long x, 
                LongBinaryOperator accumulatorFunction)
```

Atomically updates (with memory effects as specified by[VarHandle.compareAndSet(Object)](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`                   | `long`: the update value <br />                                           |
| `accumulatorFunction` | `LongBinaryOperator`: a side-effect-free function of two arguments <br /> |

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

### getAndAdd

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

```
public final long getAndAdd (long delta)
```

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

<br />

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

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

### getAndDecrement

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

```
public final long getAndDecrement ()
```

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

Equivalent to`getAndAdd(-1)`.

<br />

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

### getAndIncrement

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

```
public final long getAndIncrement ()
```

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

Equivalent to`getAndAdd(1)`.

<br />

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

### getAndSet

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

```
public final long getAndSet (long newValue)
```

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

<br />

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

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

### getAndUpdate

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

```
public final long getAndUpdate (LongUnaryOperator updateFunction)
```

Atomically updates (with memory effects as specified by[VarHandle.compareAndSet(Object)](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` | `LongUnaryOperator`: a side-effect-free function <br /> |

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

### getOpaque

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

```
public final long getOpaque ()
```

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

<br />

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

### getPlain

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

```
public final long getPlain ()
```

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

<br />

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

### incrementAndGet

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

```
public final long incrementAndGet ()
```

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

Equivalent to`addAndGet(1)`.

<br />

|             Returns              ||
|--------|--------------------------|
| `long` | 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`AtomicLong`as an`int`after a narrowing primitive conversion, with memory effects as specified by[VarHandle.getVolatile](https://developer.android.com/reference/java/lang/invoke/VarHandle#getVolatile(java.lang.Object[])).

<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 (long newValue)
```

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

<br />

|                Parameters                ||
|------------|------------------------------|
| `newValue` | `long`: 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`AtomicLong`as a`long`, with memory effects as specified by[VarHandle.getVolatile](https://developer.android.com/reference/java/lang/invoke/VarHandle#getVolatile(java.lang.Object[])). Equivalent to[get()](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicLong#get()).

<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 (long newValue)
```

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

<br />

|                Parameters                ||
|------------|------------------------------|
| `newValue` | `long`: 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 (long newValue)
```

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

<br />

|                Parameters                ||
|------------|------------------------------|
| `newValue` | `long`: 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 (long 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` | `long`: 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 (long newValue)
```

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

<br />

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

### toString

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

```
public String toString ()
```

Returns the String representation of the current value.

<br />

|                                                          Returns                                                          ||
|--------------------------------------------------------------------|-------------------------------------------------------|
| [String](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 long updateAndGet (LongUnaryOperator updateFunction)
```

Atomically updates (with memory effects as specified by[VarHandle.compareAndSet(Object)](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` | `LongUnaryOperator`: a side-effect-free function <br /> |

|             Returns              ||
|--------|--------------------------|
| `long` | 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 (long expectedValue, 
                long 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[compareAndExchange(long, long)](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicLong#compareAndExchange(long,%20long))and[compareAndSet(long, long)](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicLong#compareAndSet(long,%20long))). To avoid confusion over plain or volatile memory effects it is recommended that the method[weakCompareAndSetPlain(long, long)](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicLong#weakCompareAndSetPlain(long,%20long))be used instead.

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

<br />

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

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

**See also:**

- [weakCompareAndSetPlain(long, long)](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicLong#weakCompareAndSetPlain(long,%20long))  

### weakCompareAndSetAcquire

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

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

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

<br />

|                     Parameters                     ||
|-----------------|-----------------------------------|
| `expectedValue` | `long`: the expected value <br /> |
| `newValue`      | `long`: 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 (long expectedValue, 
                long newValue)
```

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

<br />

|                     Parameters                     ||
|-----------------|-----------------------------------|
| `expectedValue` | `long`: the expected value <br /> |
| `newValue`      | `long`: 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 (long expectedValue, 
                long newValue)
```

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

<br />

|                     Parameters                     ||
|-----------------|-----------------------------------|
| `expectedValue` | `long`: the expected value <br /> |
| `newValue`      | `long`: 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 (long expectedValue, 
                long newValue)
```

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

<br />

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

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