Class Categories{
private final int id;
private final String content;
//constructor
//getters
}
Map<Integer, String> map = categories.stream().collect( Collectors.toMap(Category::getId, Category::getContent, (a,b) -> a ) )
How to map a simple object into a map using collectors from java 8.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.