Java DoubleAccumulator longValue()方法及示例
Java.DoubleAccumulator.longValue() 是java中的一个内置方法,在缩小原始转换后,将当前值作为 long 返回。这意味着初始数据类型是double,它被明确地转换为long类型。
语法
public long longValue()
参数: 该方法不接受任何参数。
返回值: 该方法在缩小基元转换后将当前值作为long返回。
下面的程序说明了上述方法。
程序1 :
// Java program to demonstrate the// longValue() 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 longValue operation System.out.println("Old value is: " + num); // Print after longValue operation System.out.println("Current long value is: " + num.floatValue()); }}
输出:
Old value is: 52.0Current long value is: 52.0
程序2
// Java program to demonstrate the// longValue() 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(26); num.accumulate(45); // Print before longValue operation System.out.println("Old value is: " + num); // Print after longValue operation System.out.println("Current long value is: " + num.floatValue()); }}输出:
Old value is: 71.0Current long value is: 71.0
