import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
 
public class FlatmapTest {
 
    @Test
    public void test() {
        Map<Integer, Map<String, Integer>> map = new HashMap<>();
        Map<String, Integer> map1 = new HashMap<>();
        map1.put("a", 1);
        map1.put("b", 2);
        map.put(1, map1);
 
        map1 = new HashMap<>();
        map1.put("c", 3);
        map1.put("d", 4);
        map.put(2, map1);
 
        Integer sum = map.values().stream()
                .map(Map::values)
                .flatMap(i -> i.stream())
                .reduce(0, Integer::sum);
 
        System.out.println(sum);
    }
}

Output
10