Java 8 Stream – The peek() is not working with count()?

Many examples are using the .count() as the terminal operation for .peek(), for example: Java 8 List<String> l = Arrays.asList("A", "B", "C", "D"); long count = l.stream().peek(System.out::println).count(); System.out.println(count); // 4 Output – It’s working fine. A B C D 4 However, for Java 9 and above, the peek() may print nothing: Java 9 and above …

Read more

Java – Count the number of items in a List

In Java, we can use List.size() to count the number of items in a List package com.mkyong.example; import java.util.Arrays; import java.util.List; public class JavaExample { public static void main(String[] args) { List<String> list = Arrays.asList("a", "b", "c"); System.out.println(list.size()); } } Output 3 References Java doc – List

MongoDB – group, count and sort example

Some MongoDB examples to show you how to perform group by, count and sort query. 1. Test Data A whois_range collection, containing many records. > db.whois_range.find(); { "_id" : 1, "country" : "us", "source" : "ARIN", "status" : "NEW", "createdDate" : ISODate("2016-05-03T08:52:32.434Z") }, { "_id" : 2, "country" : "us", "source" : "ARIN", "status" : …

Read more