For the datas below:
List<Object> objs = JSON.parse("[
{\"type\": \"fruit\"},{\"type\": \"fruit\"},
{\"type\": \"fruit\"},{\"type\": \"meat\"},
{\"type\": \"meat\"},{\"type\": \"fruit\"},
{\"type\": \"meat\"},{\"type\": \"fruit\"}
]");
How to use stream to split these datas with type? The following code will work
objs
.parallelStream()
.collect(Collectors.groupingby(v -> v.getString("type")))
.entrySet()
.stream(entry -> {
... // part1
})
But this means these datas stream will not pass to part1 until collect end. Is there any ways to distribute stream like 'group by'?