I query the DB for two columns where the first one is the key to the second one. How can I convert the resulting list to a single map? Is it even possible? I have just seen
You forgot to convert your key and value mappings to produce String:
final Map result = steps
.stream()
.collect(Collectors.toMap(s -> (String) s.get("key"), s -> (String) s.get("value")));
Full example
public static void main(String[] args) {
final List
Which prints
key1 -> value1
key2 -> value2
key0 -> value0
key5 -> value5
key6 -> value6
key3 -> value3
key4 -> value4
key9 -> value9
key7 -> value7
key8 -> value8