Questions tagged [mutablemap]
40 questions
28
votes
2 answers
Kotlin basics: how to add or set an element of a Map?
I'd like to add/set elements of a mutable map with specific key-value pairs.
So far, I figured out that I can can add new elements using the plus operator along with the Pair data type:
var arr3:Map = mutableMapOf()
arr3 +=…

Gergely Lukacsy
- 2,881
- 2
- 23
- 28
5
votes
1 answer
How to send MutableMap from activity to another with intent
I have mutable Map as private var optionsList: MutableMap> = mutableMapOf() and i need to send it to another activity , i used this :
val optionsIntent = Intent(this@MainActivity, OptionsActivity::class.java)
…

Ahmed Wagdi
- 3,913
- 10
- 50
- 116
3
votes
1 answer
Kotlin sorting Mutable map of strings
Why cannot I sort a mutable map of string. My map is declared as follows.
val schedule: MutableMap>
It gives me schedule object as follows.
{1=[1], 0=[0], 3=[3], 2=[2], 5=[5], 4=[4, 14.07, 16.07, 01.08, 10.08],…

humble_pie
- 119
- 10
2
votes
1 answer
How to put a consumer in a map in Kotlin?
I come from java and I'm new in kotlin.
I was trying to create a map and put a consumer inside as in these…

tryingtobeabetterdev
- 23
- 4
2
votes
5 answers
Why is the sum of two mutable maps in kotlin a map
I have two functions that return mutable maps
fun mumapone() = mutableMapOf("one" to 1)
fun mumaptwo() = mutableMapOf("two" to 1) + mumapone()
the type of fun mumaptwo() becomes a Map and not a MutableMap, why? It seems…

Goozo
- 910
- 2
- 11
- 28
2
votes
0 answers
How to access values from kotlin MutableMap?
I am using Kotlin to access the response from a DialogFlow agent. The response in android console is as follows,
parameters {
fields {
key: "EmployeeID"
value {
number_value: 12345.0
}
}
}
In kotlin, I am using SessionClient…

Shujath
- 846
- 1
- 8
- 22
2
votes
0 answers
Enum as key to a mutable map in Scala
I'm trying how to figure out and work with maps with enums as keys in Scala. Looking at this question, I can instantiate maps, but when I try to update the map in place, I get a type mismatch error. What is going on here?
object MyEnums extends…

bill_e
- 930
- 2
- 12
- 24
1
vote
2 answers
Kotlin Map and Compute Functions
I am trying to re-compute values for all entries in a mutable map without changing the keys.
Here is the code (with comments showing what I am expecting)
fun main(args: Array) {
var exampleMap: MutableMap = mutableMapOf(1…

ha9u63a7
- 6,233
- 16
- 73
- 108
1
vote
2 answers
How to iterate over a Map in Kotlin
So I am new to Kotlin and I am wondering what's the standard way of iterating a Map. I have tried different ways and all of them seem to work, but I don't know if there's one better than the rest or there are some differences that I am not aware…

Bryan Oncoy
- 13
- 3
1
vote
1 answer
Map withDefault not wokring kotlin?
I have a mutable map in which I want a default value 0 for key not found
I tried the below code withDefault({somevalue})but still returns null
val attributes = mutableMapOf

WISHY
- 11,067
- 25
- 105
- 197
1
vote
5 answers
How to create a MutableMap with all keys initially set to same value in Kotlin?
I want to create a mutable map whose keys fall in a continuous range, and values initially set to the same value 9 in a single line using Kotlin. How to do that?

vagdevi k
- 1,478
- 9
- 25
1
vote
1 answer
How to increment an Int value in a Map with getOrElseUpdate?
I can update a mutable.Map value with +=:
scala> val map = mutable.Map[Int,Int]()
map: scala.collection.mutable.Map[Int,Int] = Map()
scala> map(5) = 5
scala> map
res55: scala.collection.mutable.Map[Int,Int] = Map(5 -> 5)
scala> map(5) +=…

electrickster
- 55
- 5
1
vote
0 answers
Spark Scala Job Experienceing long running tasks in final Job
I have a Spark Scala Job on EMR that runs smoothly up until the last job, then in that last job I see no progress for 2hrs. All executors show that tasks are evenly spread out so I dont think it's a data skew issue. The job was completing but I…

sgallagher
- 137
- 10
1
vote
2 answers
Safe to use (non-thread-safe) mutableMap in suspend function?
I'm learning Coroutines in Kotlin and I have a piece of code that looks like this (see below).
My friend says that the mutableMapOf is LinkedHashMap, which is not thread safe. The argument is that the suspend function may be run by different…

Gary
- 11
- 4
1
vote
1 answer
Increment element in mutable map in Kotlin
I am coming to Kotlin 1.3 from Scala. I am trying to do something very simple:
class Foo {
fun bar() {
val map = mutableMapOf()
val index = "foo"
if (index !in map)
map[index] = 0
else
…

Urban Vagabond
- 7,282
- 3
- 28
- 31