There seems to be two errors in your code and one warning for using raw ArrayList.
The first problem on this line is:
return ((int)p.vote/10);
p.votehas a type Long, and you cannot attribute it to a type int. This can be solved with:
p -> p.vote.intValue() / 10
The second problem is that the variable resmust be of type Long[]not Integer[].
Finally, the warning can be erased by changing this:
ArrayList<Temp> t = new ArrayList();
:
ArrayList<Temp> t = new ArrayList<>();
Full code:
ArrayList<Temp> t = new ArrayList<>();
t.add(new Temp());
t.add(new Temp());
t.add(new Temp());
Map<Integer, Long> counters =
t.stream()
.collect(Collectors.groupingBy(p -> p.vote.intValue()/10,
Collectors.counting()));
Collection<Long> values = counters.values();
Long[] res = values.toArray(new Long[values.size()]);
source
share