Map<Integer, Long> map = Arrays .stream(nums) .boxed() // this .collect(Collectors.groupingBy(e -> e, Collectors.counting()));