如何得到/放Kotlin内地图或地图的地图
任何人都知道我怎样才能“把/放”在kotlin内的地图?
var bookDetailsMap: MutableMap<Long, MutableMap> = mutableMapOf()
我怎样才能把以下的书籍细节放在上面的地图上?
var books: MutableList = this.bookDao.findAll()
预计存储将像>
var bookDetailsMap: MutableMap<book.publisherId, MutableMap>
成功做到这一点:
举例:
var bookDetailsMap : Map> = hashMapOf() this.bookDetailsMap = this.bookDao.findAll().groupBy { it.publisherId }.mapValues { it.value.associateBy { it.bookId} }
获取示例:
var bookDetail : BookDetail = BookDetail () if (this.bookDetailsMap .containsKey(this.publisherId)) { bookDetail = this.bookDetailsMap [this.publisherId]!![this.bookId]!! }