Maps Java Streams
Малко помощ, ако може:
Как да принтирам Value-Стойността на вложената Карта , по долу е кода.
import java.io.BufferedReader;
import java.io.IOException;
import java.util.LinkedHashMap;
public class Main {
public static void main(String[] args) throws IOException {
LinkedHashMap<String, LinkedHashMap<String, Integer>> map = new LinkedHashMap<>();
LinkedHashMap<String, Integer> nestedMap = new LinkedHashMap<>();
String country = "Bulgaria";
String city = "Sofia";
int population = 1000000;
nestedMap.put(city, population);
map.put(country, nestedMap);
map.entrySet().stream().forEach(entry -> {
System.out.printf("%s (total population: %d)%n", entry.getKey(), // TO DO Finish here);
});
}
}
Не става хвърля Exception
Bulgaria (total population: Exception in thread "main" java.util.IllegalFormatConversionException: d != java.util.LinkedHashMap
at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4302)
at java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2793)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2747)
at java.util.Formatter.format(Formatter.java:2520)
at java.io.PrintStream.format(PrintStream.java:970)
А да...сега видях. Ти имаш вътрешен мап. С това getKey трябва да ти връща него. И него трябва да обходиш.