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
Kotlin is a programming language for Android app development, and Swift is for IOS application development. Both kotlin vs swift languages are built on top of the modern programming approach and software design pattern. Both the languages offer several inbuilt functions defined in an extensive list of libraries.
String elements and templates –Elements store in a string from index 0 to (string. length – 1). Using index: Returns the character at specified index. Using get function: Returns the character at specified index passed as argument to get function.
String values must be surrounded by double quotes (" ") or triple quote (""" """). We have two kinds of string available in Kotlin - one is called Escaped String and another is called Raw String. Escaped string is declared within double quote (" ") and may contain escape characters like '\n', '\t', '\b' etc.
To create a String Array in Kotlin, use arrayOf() function. arrayOf() function creates an array of specified type and given elements.
This structure can be represented by a Map<String, Map<String, Any>>
. The Kotlin code for creating such a type:
val fromDb: 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>> fromDb = Map.of(
"Key1", Map.of("KeyA", "Value", "KeyB", "Value"),
"Key2", Map.of("KeyC", "Value", "KeyD", "Value")
);
Note that the Any
type in Kotlin is basically the same as Object
in Java.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With