What is the equivalent of [String : [String : Any]] from Swift in Kotlin or Java language?
I need to retrieve from database a structure that looks like this:
Key:
Key : Value
Key : Value
Key : Value
Key :
Key : Value
Key : Value
Key : Value
Solution:
It can be represented by a Map<String, Map<String, Any>>. The Kotlin code for creating such a type:
val map: Map<String, Map<String, Any>> = mapOf(
"Key1" to mapOf("KeyA" to "Value", "KeyB" to "Value"),
"Key2" to mapOf("KeyC" to "Value", "KeyD" to "Value")
)
In Java, as of JDK 9, it can be expressed like this:
Map<String, Map<String, Object>> map = Map.of(
"Key1", Map.of("KeyA", "Value", "KeyB", "Value"),
"Key2", Map.of("KeyC", "Value", "KeyD", "Value")
);
Note that Any from the Kotlin snippet became Object in Java.