Home > Software design >  How can I make a mutable list of mutable maps?
How can I make a mutable list of mutable maps?

Time:01-07

My attempt:

val areas = mutableListOf<mutableMapOf<Double, Double>()>()

On mutableListOf it shows an error Function invocation 'mutableListOf(...)' expected

CodePudding user response:

mutableMapOf<Double, Double>() is a function call that creates a map. You need to first create a list and only specify the type of its items, which is: MutableMap<Double, Double>:

val areas = mutableListOf<MutableMap<Double, Double>>()

Then you can add maps to it:

areas  = mutableMapOf(1.0 to 1.0)
  •  Tags:  
  • Related