I am iterating through a List of Hashmap to find the required HashMap object using the following code.
public static Map<String, String> extractMap(List<Map<String, String>> mapList, String currentIp) {
for (Map<String, String> asd : mapList) {
if (asd.get("ip").equals(currentIp)) {
return asd;
}
}
return null;
}
I was thinking about using Java 8 stream. This is the code I used to display the required object.
public static void displayRequiredMapFromList(List<Map<String, String>> mapList, String currentIp) {
mapList.stream().filter(e -> e.get("ip").equals(currentIp)).forEach(System.out::println);
}
I couldn't get the required Map from the stream using following code
public static Map<String, String> extractMapByStream(List<Map<String, String>> mapList, String currentIp) {
return mapList.stream().filter(e -> e.get("ip").equals(currentIp))
.collect(Collectors.toMap(p -> p.getKey(), p -> p.getValue()));
}
This causes syntax error Type mismatch: cannot convert from Map to Map. What do I have to put here to get Map?
List<Map<Set<String>, Map<Integer, List<HttpClient>>>>
is supposed to represent.