DoubleAccumulator intValue() method in Java with Examples

The Java.DoubleAccumulator.intValue() is an inbuilt method in java that returns the current value as an int after a narrowing primitive conversion. The initial datatype is double which is explicitly converted into type int without accepting any parameters.

Syntax:

public int intValue()

Parameters: The method does not accepts any parameter.



Return Value: The method returns the current value as an int after a narrowing primitive conversion.

Below programs illustrate the above method:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// intValue() method
  
import java.lang.*;
import java.util.concurrent.atomic.DoubleAccumulator;
  
public class GFG {
    public static void main(String args[])
    {
  
        DoubleAccumulator num
            = new DoubleAccumulator(
                Double::sum, 0L);
  
        // accumulate operation on num
        num.accumulate(42);
        num.accumulate(10);
  
        // Print before intValue operation
        System.out.println("Old value is: "
                           + num);
  
        // Print after intValue operation
        System.out.println("Current int value is: "
                           + num.intValue());
    }
}

chevron_right


Output:

Old value is: 52.0
Current int value is: 52

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// intValue() method
  
import java.lang.*;
import java.util.concurrent.atomic.DoubleAccumulator;
  
public class GFG {
    public static void main(String args[])
    {
  
        DoubleAccumulator num
            = new DoubleAccumulator(
                Double::sum, 0L);
  
        // accumulate operation on num
        num.accumulate(63);
        num.accumulate(1);
  
        // Print before intValue operation
        System.out.println("Old value is: "
                           + num);
  
        // Print after intValue operation
        System.out.println("Current int value is: "
                           + num.intValue());
    }
}

chevron_right


Output:

Old value is: 64.0
Current int value is: 64


My Personal Notes arrow_drop_up

Contented with little yet wishing for more

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.