任何人都知道如何在kotlin中“获取/放置”内部地图?
var bookDetailsMap: MutableMap<Long, MutableMap<Long, Book>> = mutableMapOf()
如何将书籍细节下方“放入”上面的地图
var books: MutableList<Book> = this.bookDao.findAll()
预计存储将类似于&gt;
var bookDetailsMap: MutableMap<book.publisherId, MutableMap<book.bookId, Book>>
答案 0 :(得分:0)
成功实现这一目标:
举例:
var bookDetailsMap : Map<Long, Map<Long, BookDetail>> = 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]!!
}