Home>

I want to get the keys ofrawMapfordbListand get a list of the keys.

Current status

rawMap// The numbers 01, 02, 03 are keys Example: rawMap.forEach {it.key}

dbList// number of elements in list is the same number as above Example: dbList.forEach {it.code}

Thinking code

Unfortunately it doesn't work

rawMap.forEach {raw->
    dbList.filterNot {db->
        raw.key.contains (db.divisionCode)
}

`

I think that it will eventually return a list while turning List and Map in a loop, but I can't come up with a good way.
I would be grateful if you could tell me if there is a good way.

  • Answer # 1

    If you want to remove what is in dbList from keys in rawMap, I think it's easy to simply take the difference.
    Reference

    val uncontainedKeys = rawMap.keys-dbList.map {it.divisionCode}

    Of course you can also write with filterNot + contains. In that case,

    val listCodes = dbList.map {it.divisionCode}
    val uncontainedKeys = rawMap.keys.filterNot (listCodes :: contains)