Questions tagged [mutablemap]

40 questions
1
vote
2 answers

counting pairs in a list

I've recently started on HackerRank and I'm attempting "Sales by Match". I've arrived at a solution I'm content with in terms of exploiting Kotlin's function programming capabilities. However, I'm not getting the expected answer... Problem…
DDisciple
  • 177
  • 1
  • 10
0
votes
3 answers

Kotlin modifying dataclass object key from map changes the reference after modifying variable

I have a MutableMap that its keys are objects from a DataClass (User dataclass), and the values are arrays from other Dataclass (Dog dataclass). If i have a variable with a User object, and i put it in the MutableMap and i test if the map contains…
0
votes
0 answers

Inject map from properties file to kotlin/java

I have data class model where I have a map and a properties file for which when the field was a String value I was mapping xyz.key = value where it would fetch and return the key and value now i have to implement this map I tried…
0
votes
1 answer

How to get the current and next item at the same time from MutableMap using Kotlin?

I would like to store information such as rowid (key) and orderId (value) in MutableMap. Then iterate through the MutableMap and get the current item key and value and the next item key and value. The reason for that is that while I am iterating…
DevPeter
  • 83
  • 2
  • 8
0
votes
1 answer

Validate request object which is a MutableMap(Map) throw exception if it's value is NULL

I have a MutableMap(map) as below in a function, let’s assume we have N no.of entries in it. I need to validate values in the map and throw exception with key if it is a Null. Please provide some suggestions on how to achieve using streams of java…
Kartheek
  • 1
  • 1
0
votes
3 answers

Having an issue with mutablemap in Kotlin

I'm working on an algorithm type challenge, and i am debugging via print statements and i can't seem to figure out why the the values for keys are not what i am expecting var mapNums = mutableMapOf() //imaginary array //var nums =…
John Doe
  • 79
  • 1
  • 4
0
votes
2 answers

kotlin idiomatic way to make it simpler when pass in a nullable mutableMap

converting from java to kotlin java code public void logEvent(String eventName, @Nullable Map customParams) { if (customParams == null) { customParams = new HashMap<>(); } …
lannyf
  • 9,865
  • 12
  • 70
  • 152
0
votes
2 answers

Better way to set all the keys to map to false in a mutable map

I have a mutable map val weeklyCheck = mutableMapOf( Day.MONDAY to true, Day.TUESDAY to true, Day.WEDNESDAY to true, Day.THURSDAY to true, Day.FRIDAY to true, Day.SATURDAY to true, Day.SUNDAY to true ) How do I set all…
A-run
  • 470
  • 4
  • 13
0
votes
2 answers

How would you return a MutableMap(HashMap) with a list parameter in a function to find the frequency of each element in the list (Kotlin)

fun main() { val list = listOf("B", "A", "A", "C", "B", "A") print(findfrequency(list)) } fun findfrequency(list: T): MutableMap { val frequencyMap: MutableMap = HashMap() for (s in list) { …
TheDevTing
  • 11
  • 2
0
votes
0 answers

what does val dict = scala.collection.mutable.Map[Int, Int]().withDefaultValue(0) mean in scala?

could anyone explain what below if statement does if (dict.contains(sum-k)) count+= dict(sum-k) dict(sum) += 1 Actual code: object Solution { def subarraySum(nums: Array[Int], k: Int): Int = { if (nums isEmpty) return 0 …
Divi
  • 1
  • 2
0
votes
1 answer

MutableList to MutableMap in Kotlin

I have a mutable list of objects that belong to custom class Expense. Class Expense has following attributes: amount category I want to create a mutable map by iterating through the list above and the result should be as follows: category_1 : sum…
ShrikeThe
  • 77
  • 6
0
votes
0 answers

Get value of key from a mutable map

I have a Map which looks as follows: val myMap = mutableMapOf() myMap.put("A", "APPLE") myMap.put("B", "BALL") myMap.put("C", "CAT") myMap.put("D", "DOG") ... When I print the map as follows, it prints it…
user10882820
0
votes
1 answer

How to call function indirectly in Kotlin

Assume I have a mutableMap: val MM = mutableMapOf() Now I define a function as a method for it: MM["testF"] = fun () { println("WOW") } Now I want to call it in another place: val MMTF = MM["testF"] as Function<*> MMTF() <-- NOT WORKING Any…
weera
  • 884
  • 1
  • 10
  • 21
0
votes
1 answer

Class Doesn't Return A MutableMap Object

I was using Kotlin to make a basic Currency converter app with an API. To download information, I have created a new class called DownloadTaskClass that extends the deprecated AsyncTask class (I haven't learned the other classes of the…
Arpan Sircar
  • 545
  • 2
  • 4
  • 15
0
votes
4 answers

How to set value to the child map in the father map in kotlin?

as title, I have the code: val description= mutableMapOf( "father2" to "123", "father" to mutableMapOf()) description["father"]["child"] = "child value" if i try this: description["father"]["child"]="child value" I will get…