Based on Collectors documentation it's as simple as:

Map<String, Choice> result =
    choices.stream().collect(Collectors.toMap(Choice::getName,
                                              Function.identity()));
Answer from zapl on Stack Overflow
๐ŸŒ
HowToDoInJava
howtodoinjava.com โ€บ home โ€บ java 8 โ€บ java stream to map with collectors.tomap() examples
Java Stream to Map with Collectors.toMap() Examples
March 18, 2019 - List<Item> itemsWithDuplicates = List.of( new Item(1, "Item1"), new Item(2, "Item2"), new Item(3, "Item3-1"), new Item(3, "Item3-2"), new Item(3, "Item3-3")); Map<Long, String> fails = itemsWithDuplicates.stream() .collect(Collectors.toMap(Item::id, Item::name)); // IllegalStateException: Duplicate key 3 (attempted merging values Item3-1 and Item3-2) Exception in thread "main" java.lang.IllegalStateException: Duplicate key 3 (attempted merging values Item3-1 and Item3-2) at java.base/java.util.stream.Collectors.duplicateKeyException(Collectors.java:135) at java.base/java.util.stream.Collectors.lambda$uniqKeysMapAccumulator$0(Collectors.java:182)
๐ŸŒ
Medium
medium.com โ€บ geekculture โ€บ java-streams-collect-to-map-of-lists-with-grouping-by-8cb309df4598
Java Streams: Collect to Map of Lists with Grouping By | Geek Culture
May 7, 2022 - How to collect a stream into a map of lists, to avoid duplicate key exception, using the Collectors . groupingBy method method reference lambda functions
Discussions

lambda - Java 8 List<V> into Map<K, V> - Stack Overflow
I want to translate a List of objects into a Map using Java 8's streams and lambdas. This is how I would write it in Java 7 and below: private Map nameMap(List c... More on stackoverflow.com
๐ŸŒ stackoverflow.com
collections - Java 8 stream map to list of keys sorted by values - Stack Overflow
Fantasy trilogy where the main character Jack is able to travel between our world and a fantasy realm ยท Who can challenge designations of people or organizations as terrorists? tcolorbox suboptimal connexion with dotted borderline ยท Was the submarine carrier of the Ulysses bigger than the SS Great Eastern? Speeding up computation of binomials with Java... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Convert a list of maps to a map of lists using Java Streams - Stack Overflow
CopyList> data ... List> result = new HashMap<>(); for (Map element: data) { element.forEach((key, val) -> { if (result.containsKey(key)) result.get(key).add(val); else result.put(key, Arrays.asList(val)); }); } How would I be able to achieve the same result using streams? ... Save this answer. ... Show activity on this post. E.g. like this, relying on the collect stage of java ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
November 3, 2020
collections - Java 8 streams - collect and stream map of lists - Stack Overflow
I have a Map of Lists, and would like to collect all the values and then stream on the collected List, so given:- Map effectiveDatePublicationM... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
amitph
amitph.com โ€บ home โ€บ java โ€บ examples of converting list to map using streams
Examples of Converting List to Map using Streams | amitph
November 22, 2024 - The Java Stream Collectors.toMap() is a convenient method for creating maps. The method accepts two Functions โ€“ the first for mapping the key and the other for mapping the value.
๐ŸŒ
Marc Nuri
blog.marcnuri.com โ€บ home โ€บ java streams: convert list into map
Java Streams: Convert List into Map - Marc Nuri
January 27, 2026 - Convert a List to a Map using Java Streams and Collectors.toMap(). Covers handling duplicates, order, immutable maps, and null values.
Find elsewhere
๐ŸŒ
Medium
medium.com โ€บ @AlexanderObregon โ€บ javas-stream-map-method-explained-df0d0d461d39
Javaโ€™s Stream.map() Method Explained | Medium
August 27, 2024 - Here, the map() method applies the Integer::parseInt function to each string in the list, converting it into an integer. The resulting stream is then collected into a list of integers.
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ java-convert-map-to-list
Java 8: How to Convert a Map to List
October 10, 2023 - Java 8 introduced us to the Stream ... the key-value mappings of a Map, while still converting it into a List would be to stream() the entries, which consist of the key-value pairs....
๐ŸŒ
Medium
neesri.medium.com โ€บ how-to-convert-a-stream-to-list-set-map-and-different-types-of-collections-1902c849e34a
How to Convert a Stream to List, Set, Map and different types of collections. | by A cup of JAVA coffee with NeeSri | Medium
July 25, 2025 - In Java, Streams are powerful tools that allow you to process collections in a functional way. You can convert a Stream into different types of collections like List, Set, or Map using the Collectors class.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java collections โ€บ java map โ€บ java collectors tomap
Java Collectors toMap | Baeldung
February 26, 2026 - The article discusses Java 8 Collectors, showing examples of built-in collectors, as well as showing how to build custom collector. ... Learn how to collect Java Streams to immutable Collections. ... Weโ€™ll start with the simplest case, by transforming a List into a Map.
๐ŸŒ
Blogger
javarevisited.blogspot.com โ€บ 2016 โ€บ 04 โ€บ 10-examples-of-converting-list-to-map.html
10 Examples of Converting a List to Map in Java 8
private Map<String, Choice> toMap(List books) { final Map hashMap = new HashMap<>(); for (final Book book : books) { hashMap.put(book.getISBN(), book); } return hashMap; } You can see we have iterated through the List using enhanced for loop of Java 5 and put each element into a HashMap, where ISBN code is the key, and the book object itself is the value. This is the best way to convert a List to Map in pre-JDK 8 worlds. It's clear, concise, and self-explanatory, but iterative. Now, let's see how we can do the same in Java 8 by using lambda expression and Stream API, here is my first attempt:
๐ŸŒ
Java67
java67.com โ€บ 2019 โ€บ 05 โ€บ how-to-convert-stream-to-list-set-map-in-java.html
How to Convert a Stream to List, Set, and Map in Java? Example Tutorial | Java67
Our complete Java program demonstrates how you can use the Collectors class to convert a Stream of values into List, Set, Map, and ConcurrentMap in Java. Not only you will learn to convert Stream to generic Collection classes but also specific ones like ArrayList, LinkedList, HashMap, HashSet, LinkedHashMap, and TreeMap.
Top answer
1 of 4
3

Just make sure array has unique titles and then use Collectors.toMap

Map<String, List<String>> result = Arrays.stream(myStringArray)
            .map(title -> new AbstractMap.SimpleEntry<>(title,
                    pages.stream().filter(page -> isPageContainsTitle(page,title)).collect(Collectors.toList())))
            .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

And as @Naman suggested you can avoid the intermediate map operation

Map<String, List<String>> result = Arrays.stream(myStringArray) 
                     .collect(Collectors.toMap(Function.identity() 
                                        ,title -> pages.stream()
                                                       .filter(page -> isPageContainsTitle(page, title))
                                                       .collect(Collectors.toList())));
2 of 4
2

Below code should work for you:

package com.shree.test;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class StreamTest {
    public static void main(String[] args) {
        String[] myStringArray = {"TITLE1", "TITLE2", "TITLE3"};
        List<String> pages = new ArrayList<>();
        pages.add("TEXT,TITLE2,TEXT,ONE,TWO");
        pages.add("TEXT,TITLE1,TEXT,ONE,TWO");
        pages.add("TEXT,TITLE2,TEXT,ONE,TWO");
        pages.add("TEXT,TITLE2,TEXT,TITLE3,TWO");
        pages.add("TEXT,TITLE3,TEXT,ONE,TWO");



         Map<Object, Object> titleMap = getTitleMap(myStringArray, pages);

         titleMap.entrySet().forEach(System.out::println);
    }

    private static Map<Object, Object> getTitleMap(String[] myStringArray, List<String> pages) {
        Map<Object, Object> titleMap = Arrays.asList(myStringArray).stream()
            .map(
                    (title)->{
                        return new AbstractMap.SimpleEntry<>(title, pages.stream()
                                .filter((page)->page.contains(title))
                                .collect(Collectors.toList()));
                    }
                )
            .collect(Collectors.toMap(entry->entry.getKey(), entry->entry.getValue()));
        return titleMap;
    }
}
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 680277 โ€บ java โ€บ Creating-map-maps-list-Java
Creating a map of maps from a list using Java 8 streams [Solved] (Java in General forum at Coderanch)
The key of the first map is MonitoredData::getDayOfYear and the key to the second map is MonitoredData::getActivityLabel. The value of the second data should be the number of times the certain activity has been found in that specific day. Thanks in advance, tell me if there's something else ...
๐ŸŒ
How to do in Java
howtodoinjava.com โ€บ home โ€บ collections framework โ€บ convert list to map in java: tomap(), duplicate keys and order
Convert List to Map in Java: toMap(), Duplicate Keys and Order
September 23, 2022 - To convert a List to a Map in Java, we stream the list and collect it with Collectors.toMap(keyMapper, valueMapper), which turns every element into one key-value entry. When several elements can produce the same key, we either pass a merge function ...
๐ŸŒ
Reddit
reddit.com โ€บ r/javahelp โ€บ need help with creating a map from a list with stream
r/javahelp on Reddit: Need help with creating a map from a list with stream
September 28, 2023 -

I have a list of objects (let's say object has string a, string b, string c ) need to convert it into map with key as a+b and value as entire object. Is this possible? Please help.

I m trying like this syntax: list.stream().collect(Collectors.toMap(key, value)); But not able to set key value as concatenation of a and b.