To get the description frequencies of class objects:
public class Tag {
private int excerptID;
private String description;
}
I use Collectors groupingBy + counting functions:
Map<String, Long> frequencyMap = rawTags.stream().map(Tag::getDescription).collect(Collectors.groupingBy(e -> e, Collectors.counting()));
But I want to return the result as a new object of the class
public class Frequency {
private String Description;
private Long frequency;
}
instead of Map<String, Long>
. What is a simple way to do it?
You can get
entrySet
of map and transform into Frequency class and collect as List.Or using
Collectors.collectingAndThen