Is there a function in java to get moving average

后端 未结 7 1787
囚心锁ツ
囚心锁ツ 2020-12-14 16:14

I have a situation where I need to process 5000 samples from a device in every 0.5 sec.

Lets say the window size is 100, then there would be 50 points resulting fro

7条回答
  •  有刺的猬
    2020-12-14 16:57

    Java 8 has added java.util.IntSummaryStatistics. There similar classes for Double and Long as well. Fairly straightforward to use:

    IntSummaryStatistics stats = new IntSummaryStatistics();
    stats.accept(1);
    stats.accept(3);
    stats.getAverage(); // Returns 2.0
    

提交回复
热议问题