You can use the Streams API :

List<Object> multiFieldsList = 
    multiFieldMap.entrySet()
                 .stream()
                 .flatMap(e -> e.getValue()
                                .stream()
                                .map(o -> queryService.query(e.getKey(), queryService.property("id").eq(o))))
                 .collect(Collectors.toList());
Answer from Eran on Stack Overflow
🌐
Dev.java
dev.java › learn › handling-map-values-with-lambda-expressions
Handling Map Values with Lambda Expressions
Java Platform Evolution · Using JDK Preview Features · Language Basics · Object Oriented Programming · Generics, Lambda, and Pattern Matching · Annotations and Exceptions · Collections and Streams · Managing Out-of-Memory Data · Managing Dates and Regular Expressions ·
🌐
TutorialsPoint
tutorialspoint.com › how-to-populate-a-map-using-a-lambda-expression-in-java
How to populate a Map using a lambda expression in Java?\\n
import java.util.*; public class PopulateUsingMapLambdaTest { public static void main(String[] args) { Map<Character, Runnable> map = new HashMap<>(); map.put('h', () -> System.out.println("Type h or q")); // lambda expression map.put('q', () -> System.exit(0)); // lambda expression while(true) { System.out.println("Menu"); System.out.println("h) Help"); System.out.println("q) Quit"); char key = new Scanner(System.in).nextLine().charAt(0); if(map.containsKey(key)) map.get(key).run(); } } }
🌐
Medium
medium.com › @AlexanderObregon › javas-stream-map-method-explained-df0d0d461d39
Java’s Stream.map() Method Explained | Medium
August 27, 2024 - At its core, the map() method relies ... of type T and produces a result of type R. The map() method uses this function to apply a transformation to each element in the stream....
🌐
WPI Computer Science
web.cs.wpi.edu › ~cs2102 › b15 › Labs › map-and-filter.html
Map, Filter, Lambdas and Java Streams
In Friday’s class, you saw how to pass predicates (lambdas) as arguments in Java. This lab shows you how to use this with Java’s versions of map and filter.
🌐
GeeksforGeeks
geeksforgeeks.org › java › converting-arraylist-to-hashmap-in-java-8-using-a-lambda-expression
Converting ArrayList to HashMap in Java 8 using a Lambda Expression - GeeksforGeeks
January 23, 2026 - Iterate over the list using a lambda expression. Insert elements into the map using map.put(key, value). Print the resulting map. ... import java.util.*; class ListItems { private Integer key; private String value; public ListItems(Integer key, ...
🌐
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] } }
🌐
Java67
java67.com › 2015 › 01 › java-8-map-function-examples.html
Java 8 Stream map() function Example with Explanation | Java67
That's why you can pass any function whether it's a proper method or a shortcut code using lambda expression which can convert one type to other. The important detail to remember is that the argument type is T and the return type is R. And, if you look at the return type of map() function then its <R> Stream<R>, which is a stream of R, the same type which the function you passed to the map() method returns. The R is also the type of Stream on which you call the map function. In this Java 8 tutorial, we have used the map function for two examples, first to convert each element of List to upper case, and second to square each integer in the List.
Find elsewhere
🌐
BeginnersBook
beginnersbook.com › 2017 › 01 › lambda-expression-iterating-map-and-list-in-java-8
Lambda Expression – Iterating Map and List in Java 8
package com.beginnersbook; import java.util.HashMap; import java.util.Map; public class IterateMapUsingLambda { public static void main(String[] args) { Map<String, Integer> prices = new HashMap<>(); prices.put("Apple", 50); prices.put("Orange", 20); prices.put("Banana", 10); prices.put("Grapes", 40); prices.put("Papaya", 50); /* Iterate without using Lambda for (Map.Entry<String, Integer> entry : prices.entrySet()) { System.out.println("Fruit: " + entry.getKey() + ", Price: " + entry.getValue()); } */ prices.forEach((k,v)->System.out.println("Fruit: " + k + ", Price: " + v)); } }
🌐
Apache
nightlies.apache.org › flink › flink-docs-master › docs › dev › datastream › java_lambdas
Java Lambda Expressions | Apache Flink
Flink supports the usage of lambda expressions for all operators of the Java API, however, whenever a lambda expression uses Java generics you need to declare type information explicitly. This document shows how to use lambda expressions and describes current limitations. For a general introduction to the Flink API, please refer to the DataStream API overview · The following example illustrates how to implement a simple, inline map() function that squares its input using a lambda expression.
🌐
DZone
dzone.com › data engineering › data › creating maps with named lambdas
Creating Maps With Named Lambdas
December 7, 2016 - We can only create maps with keys that are of type String (or anything super String like CharSequence, Serializable, or Comparable<String>) because, obviously, lambda names are strings. We must use a Java version that is higher than Java 8u80 because it was at that time that lambda names could be retrieved at runtime.
🌐
TutorialsPoint
tutorialspoint.com › article › how-can-we-iterate-the-elements-of-list-and-map-using-lambda-expression-in-java
How can we iterate the elements of List and Map using lambda expression in Java?
import java.util.*; public class ListIterateLambdaTest { public static void main(String[] argv) { List<String> countryNames = new ArrayList<String>(); countryNames.add("India"); countryNames.add("England"); countryNames.add("Australia"); countryNames.add("Newzealand"); countryNames.add("South Africa"); // Iterating country names through forEach using Lambda Expression countryNames.forEach(name -> System.out.println(name)); } } ... import java.util.*; public class MapIterateLambdaTest { public static void main(String[] args) { Map<String, Integer> ranks = new HashMap<String, Integer>(); ranks.put("India", 1); ranks.put("Australia", 2); ranks.put("England", 3); ranks.put("Newzealand", 4); ranks.put("South Africa", 5); // Iterating through forEach using Lambda Expression ranks.forEach((k,v) -> System.out.println("Team : " + k + ", Rank : " + v)); } }
🌐
W3Schools
w3schools.com › java › java_lambda.asp
Java Lambda Expressions
The variable's type must be an interface with exactly one method (a functional interface). The lambda must match that method's parameters and return type. Java includes many built-in functional interfaces, such as Consumer (from the java.util package) used with lists.
🌐
CodingBat
codingbat.com › doc › java-functional-mapping.html
Java Functional Mapping
The stream() call sets up the list for mapping. That call is followed by any number of map(lambda) calls to map (or filter) the item values as we have done. Finally the collect() call collapses the stream down to a list or set or whatever, which is returned. The stream system returns a new ...
🌐
TutorialsPoint
tutorialspoint.com › article › java-program-to-initialize-a-hashmap-with-lambda-expressions
Java Program to initialize a HashMap with Lambda Expressions
Here, the lambda expressions will define the Callable objects that are stored as values in the HashMap. import java.util.HashMap; import java.util.concurrent.Callable; public class Demo { public static void main(String[] args) throws Exception { // initialize HashMap with Integer keys and Callable values HashMap<Integer, Callable<Integer>> map = new HashMap<Integer, Callable<Integer>>() { { // adding values put(0, () -> 10); put(1, () -> 20); put(2, () -> 30); put(3, () -> 40); } }; // calling callable to print result System.out.println(map.get(0).call()); System.out.println(map.get(1).call()); System.out.println(map.get(2).call()); System.out.println(map.get(3).call()); } }
🌐
Oracle
docs.oracle.com › javase › tutorial › java › javaOO › lambdaexpressions.html
Lambda Expressions (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
Filters objects that match the Predicate object tester. In this example, the Predicate object is a lambda expression that specifies which members would be eligible for Selective Service. Maps each filtered object to a value as specified by the Function object mapper.
🌐
Bala's Blog
dkbalachandar.wordpress.com › 2018 › 02 › 19 › java-8-lambda-using-map
Java 8 Lambda – Using Map | Bala's Blog - WordPress.com
February 19, 2018 - In this post, I am going to show some examples of using Java 8 Stream map(). I have an arraylist which contains list of strings and want to change the contents of that list to upper case. We can easily do that with map() but I want to make sure that my code should work…
Top answer
1 of 4
12

If you want to initialize a Map in a single statement, you can use Collectors.toMap.

Imagine you want to build a Map<Integer, Boolean> mapping an integer to the result of calling some function f:

private static final Map<Integer,Boolean> MAP = 
        Collections.unmodifiableMap(IntStream.range(0, 1000)
                                             .boxed()
                                             .collect(Collectors.toMap(i -> i, i -> f(i))));

private static final boolean f(int i) {
    return Math.random() * 100 > i;
}

If you want to initialize it with "static" known values, like the example in your answer, you can abuse the Stream API like this:

private static final Map<Integer, Boolean> MAP = 
       Stream.of(new Object[] { 1, false }, new Object[] { 2, true })
             .collect(Collectors.toMap(s -> (int) s[0], s -> (boolean) s[1]));

Note that this is a real abuse and I personally would never use it: if you want to construct a Map with known static values, there is nothing to gain from using Streams and you would be better off to use a static initializer.

2 of 4
6

Here is how to implement a field initializer in Java 8 in a single statement using a lambda.

private static final Map<Integer,Boolean> map =
        ((Supplier<Map<Integer,Boolean>>)() -> {
            Map<Integer,Boolean> mutableMap = new HashMap<>();
            mutableMap.put( 1, false );
            mutableMap.put( 2, true );
            return Collections.unmodifiableMap( mutableMap );
        }).get();

Java 9 solution:

private static final Map<Integer,Boolean> map = Map.of( 1, false, 2, true );

and if you have more than 10 entries, Map.of() won't work, so you need this:

private static final Map<Integer,Boolean> map = Map.ofEntries( 
        Map.entry( 1, false ), 
        Map.entry( 2, true ), 
        Map.entry( 3, false ), 
        Map.entry( 4, true ), 
        Map.entry( 5, false ), 
        Map.entry( 6, true ), 
        Map.entry( 7, false ), 
        Map.entry( 8, true ), 
        Map.entry( 9, false ), 
        Map.entry( 10, true ), 
        Map.entry( 11, false ) );
🌐
Baeldung
baeldung.com › home › java › java collections › java map › working with maps using streams
Working With Maps Using Streams | Baeldung
November 10, 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.