lambda - Find maximum, minimum, sum and average of a list in Java 8 -


how find maximum, minimum, sum , average of numbers in following list in java 8?

list<integer> primes = arrays.aslist(2, 3, 5, 7, 11, 13, 17, 19, 23, 29); 

there class name, intsummarystatistics

for example:

  list<integer> primes = arrays.aslist(2, 3, 5, 7, 11, 13, 17, 19, 23, 29);   intsummarystatistics stats = primes.stream()                                      .maptoint((x) -> x)                                      .summarystatistics();   system.out.println(stats); 

output:

   intsummarystatistics{count=10, sum=129, min=2, average=12.900000, max=29} 

hope helps

read intsummarystatistics


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -