Kotlin - Map with Multiple Keys - Example
Today we will show you how to implement a Map with Multiple Keys. Solution 1: Using Kotlin Custom Key Class Solution 2: Using Google's Guava Solution 3: Using Apache Commons Collections Example 1: Using Kotlin Custom MultiMapKey Here we created a custom MultiMap Key class, we can use MultiMap as a Key to map a value. object MultiKeyDemo { @JvmStatic fun main(args: Array<String>) { // Declaring the Map val table: MutableMap<MultiMapKey, String> = HashMap() // Declaring the key objects val key1 = MultiMapKey( "raw1" , "col1" ) val key2 = MultiMapKey( "raw1" , "col2" ) val key3 = MultiMapKey( "raw1" , "col3" ) // Putting the values table[key1] = "Java" table[key2] = "Kotlin" table[key3] = "Android" // Getting value by key val value2 = table[key2] println(value2) ...