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())));
Answer from Ryuzaki L on Stack Overflow
🌐
Mkyong
mkyong.com › home › java8 › java 8 streams map() examples
Java 8 Streams map() examples | mkyong.com
April 3, 2017 - package com.mkyong.java8; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; public class TestJava8 { public static void main(String[] args) { List<Staff> staff = Arrays.asList( new Staff("mkyong", 30, new BigDecimal(10000)), new Staff("jack", 27, new BigDecimal(20000)), new Staff("lawrence", 33, new BigDecimal(30000)) ); //Before Java 8 List<String> result = new ArrayList<>(); for (Staff x : staff) { result.add(x.getName()); } System.out.println(result); //[mkyong, jack, lawrence] //Java 8 List<String> collect = staff.stream().map(x -> x.getName()).collect(Collectors.toList()); System.out.println(collect); //[mkyong, jack, lawrence] } } 3.1 This example shows you how to convert a list of staff objects into a list of StaffPublic objects.
🌐
Roy Tutorials
roytuts.com › home › java › convert list of map objects into list of objects using java stream
Convert List of Map Objects Into List Of Objects Using Java Stream - Roy Tutorials
October 25, 2022 - Map To List Objects Here I will show you how to convert List of Map objects into List of objects using Java 8's or later's Stream API. The List of Map
Discussions

Create list of object from another using Java 8 Streams - Stack Overflow
I'm trying to understand Java 8 streams. I have two classes: public class UserMeal { protected final LocalDateTime dateTime; protected final String description; protected final int More on stackoverflow.com
🌐 stackoverflow.com
java - Convert a List of objects to a Map using Streams - Stack Overflow
I have a list of objects of class A: List list; class A { String name; String lastname; //Getter and Setter methods } I want to convert this list to a map from name to a set of More on stackoverflow.com
🌐 stackoverflow.com
Need help with creating a map from a list with stream
https://www.baeldung.com/java-list-to-map#after-java8 More on reddit.com
🌐 r/javahelp
7
2
September 28, 2023
java stream List<Object[]> to Map<Object, List<Object[]>> - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Save this question. Show activity on this post. I have List inner join MySQL query, I need to create a map key id and value object. The Code below works, but how to do it best with Streams? More on stackoverflow.com
🌐 stackoverflow.com
November 28, 2017
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;
    }
}
🌐
Baeldung
baeldung.com › home › java › java list › create list of object from another type using java
Create List of Object From Another Type Using Java | Baeldung
March 7, 2025 - As the code above shows, preparing an empty list for TennisPlayerCandidate objects is unnecessary. The filter().map() pipeline delivers a Stream of TennisPlayerCandidate instances.
🌐
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.
🌐
Stack Abuse
stackabuse.com › java-8-stream-map-examples
Java 8 - Stream.map() Examples
February 23, 2023 - In this tutorial, we'll go over the map() operation and how we can use it with Streams to convert/map objects of various types. Let's take a look at a couple of examples and see what we can do with the map() operation. Arrays.asList(1, 2, 3, 4).stream() .map(n -> "Number " + String.valueOf(n)) .forEach(n -> System.out.println(n + " as a " + n.getClass().getName())); Here, we've made a list of integers and called stream() on the list to create a new stream of data.
🌐
Makeinjava
makeinjava.com › home › convert list of objects to /from map in java 8 lambda stream (example)
Convert list of objects to /from map in java 8 lambda stream (with example)
January 3, 2024 - Convert Map to list of objects :"); convertMapToList(mapIdToPerson); } private static Map<String, Person> convertListToMap(List <Person> personList) { Map<String, Person>mapIdToPerson = null; mapIdToPerson = personList.stream() .collect( Collectors .toMap( Person::getUniqueId, person->person) ); System.out.println(mapIdToPerson); return mapIdToPerson; } private static void convertMapToList(Map<String, Person>mapIdToPerson) { System.out.println("2.1.
🌐
Baeldung
baeldung.com › home › java › java collections › java map › how to convert list to map in java
How to Convert List to Map in Java | Baeldung
April 4, 2025 - Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.
Find elsewhere
🌐
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.
🌐
HowToDoInJava
howtodoinjava.com › home › java 8 › java stream map()
Java Stream map() with Examples - HowToDoInJava
August 26, 2023 - mapper is a non-interfering, stateless function to apply to each element which produces a stream of new values. The method returns a new stream of objects of type R.
🌐
Marc Nuri
blog.marcnuri.com › home › java streams: convert list into map
Java Streams: Convert List into Map - Marc Nuri
January 27, 2026 - The fourth parameter is a Supplier that provides the Map implementation. LinkedHashMap maintains a doubly-linked list of entries, preserving the iteration order. To sort keys alphabetically, use a TreeMap which implements SortedMap. ... TreeMap<String, Repository> sorted = repos.stream().collect(Collectors.toMap( Repository::name, Function.identity(), (existing, replacement) -> existing, TreeMap::new ));
🌐
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.

🌐
Medium
pratiyush.medium.com › list-to-map-using-stream-and-collectors-in-java-40deef82f9c1
Convert List to Map Using Stream and Collectors in Java | by Pratiyush Prakash | Medium
September 3, 2024 - Let’s jump right into the quicker way of doing the same. List<Employee> list; // This list is given to youMap<String, Employee> map = list.stream().collect(Collectors.toMap(Employee::email, employee -> employee);// as we are using the stream, so if you want to filter your list, you can even do that.// let's take one example.
Top answer
1 of 2
3

It seems you need to group by element at index zero of an array Object

Collectors.groupingBy groups by the key

Map<Object, List<Object[]>> map = objects.stream()
    .collect(Collectors.groupingBy(o -> o[0]));

with null and empty checks

Map<Object, List<Object[]>> map = objects.stream()
    .filter(o -> o != null && o.length != 0)
    .collect(Collectors.groupingBy(o -> o[0]));

Example

List<Object[]> objects = new ArrayList<>();
objects.add(new Object[] { 0, 1, 2, 3, 4, 5 });
objects.add(new Object[] { 1, 1, 2, 3, 4, 5 });
objects.add(new Object[] { 2, 1, 2, 3, 4, 5 });
objects.add(new Object[] { 0, 6, 7, 8, 9 });

Map<Object, List<Object[]>> map = objects.stream()
    .collect(Collectors.groupingBy(o -> o[0]));

System.out.println(map);

output is like

{
    0 = [[Ljava.lang.Object;@378bf509,
            [Ljava.lang.Object;@5fd0d5ae],
    1 = [[Ljava.lang.Object;@2d98a335],
    2 = [[Ljava.lang.Object;@16b98e56]
}

you can see 0 has two List<Object[]> values grouped by

2 of 2
0

I would make the whole procedure more explicit and clean. Using a mixed-style with lots of comments and good variable names.

This should help a lot when it comes down to reading, understanding and maintaining your code.

Map<Object, List<Object[]>> convert(List<Object[]> entities) {
    Map<Object, List<Object[]>> idToEntitesWithSameId = new HashMap<>();

    entities.forEach(entity -> {
        // Create an entry for each entity,
        // merge with entities of same id
        Object id = entity[0];

        // Get current value or empty list
        List<Object[]> entitiesWithId = idToEntitesWithSameId
            .computeIfAbsent(id, ArrayList::new);

        // Add own entity, merge with other
        // entities of same id
        Arrays.stream(entity).forEach(entitiesWithId::add);
    });

    return idToEntitesWithSameId;
}
🌐
GeeksforGeeks
geeksforgeeks.org › java › program-to-convert-list-to-map-in-java
Program to Convert List to Map in Java - GeeksforGeeks
April 9, 2026 - Create a List of objects. Convert the List into a Stream using stream(). Use Collectors.toMap() to specify the key and value. Collect the elements into a Map. ... import java.util.*; import java.util.stream.Collectors; class Student { private ...
🌐
Medium
medium.com › @AlexanderObregon › javas-stream-map-method-explained-df0d0d461d39
Java’s Stream.map() Method Explained | Medium
August 27, 2024 - Second Transformation — Converting to Uppercase: The second map() call applies the String::toUpperCase function to each title, converting it to uppercase. The stream remains a stream of String objects, but now each string is in uppercase.