What is the AtomicInteger.doubleValue method in Java?

AtomicInteger represents an int value the may be updated atomicallyAtomic 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 AtomicInteger class is present in the java.util.concurrent.atomic package.

The doubleValue method of the AtomicInteger class will return the AtomicInteger value as a double value after a widening primitive conversion.

Syntax

public double doubleValue()

This method doesn’t take any argument.

This method returns the AtomicInteger object’s value as a double value.

Code

The below code demonstrates how to use the doubleValue method:

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

Explanation

  • In line 1: We imported the AtomicInteger class.

  • In line 4: We created a new object for the AtomicInteger class with the name atomicInteger and with the value 10.

  • In line 9: We used the doubleValue method to get the value of the atomicInteger object as a double value.

Free Resources