Skip to content

Instantly share code, notes, and snippets.

@GayanM
Created September 25, 2022 11:09
Show Gist options
  • Select an option

  • Save GayanM/0b71ac4190b9db85dd1f973a1df13087 to your computer and use it in GitHub Desktop.

Select an option

Save GayanM/0b71ac4190b9db85dd1f973a1df13087 to your computer and use it in GitHub Desktop.
Obtain a data map with list of product name by category
@RequestMapping("/product-category")
Map<String, List<String>> getProductsByCategory(List<Product> productList) {
return productRepos.findAll().stream().collect(Collectors.groupingBy(com.mycompany.functional.programming.
exercises.models.Product::getCategory, Collectors.mapping(product -> product.getName(),
Collectors.toList())));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment