What is the AtomicLong.doubleValue method in Java?

AtomicLong represents a long value the may be updated atomically

Atomic operation is performing a single unit of work on a resource. During that operation, no other operations are allowed on the same resource until the performing operation is finished.

The AtomicLong is present in the java.util.concurrent.atomic package. The doubleValue() method of the AtomicLong will return the AtomicLong value as a double value after a widening primitive conversion.

Syntax

public double doubleValue()
  • This method doesn’t take any arguments.

  • This method returns the AtomicLong object value as a double value.

Code

The code below demonstrates how to use the doubleValue() method:

import java.util.concurrent.atomic.AtomicLong;
class DoubleValue{
public static void main(String[] args) {
AtomicLong atomicLong = new AtomicLong(10);
long val = atomicLong.get();
System.out.println("The value in the atomicLong object is " + val);
double doubleVal = atomicLong.doubleValue();
System.out.println("\natomicLong.doubleValue() : " + doubleVal);
}
}

Explanation

In line 1: We import the AtomicLong class.

In line 4: We create a new object for the AtomicLong class with the name atomicLong and with the value 10.

In line 9: We use the doubleValue() method to get the value of the atomicLong object as a double value.

Free Resources