android - Kotlin Queue returning object
问题描述
I am trying to create a queue of List
so far I have this
var queue = LinkedList<Array<IntArray>>()
queue.add(arrayOf(intArrayOf(1,2,0)))
queue.add(arrayOf(intArrayOf(3,4,5)))
Log.d("debugVal",queue.poll()[0].toString())
It returns something like this
D/debugVal: [I@81fc7ad
I was expecting it to print 1
I think it's returning an object. Can someone please tell me how to retrieve the list values from the polled element I need all three of the values from each polled element
解决方案
使用该方法返回的元素queue.poll()
是 a Array<IntArray>
,而不是IntArray
。当你打电话时,queue.poll()[0]
你得到了第一个元素Array<IntArray>
,所以一个IntArray
. 如果要获取 的第一个元素IntArray
,则应调用queue.poll()[0][0]
:
var queue = LinkedList<Array<IntArray>>()
queue.add(arrayOf(intArrayOf(1, 2, 0)))
queue.add(arrayOf(intArrayOf(3, 44, 10)))
Log.d("debugVal", queue.poll()[0][0].toString())
此外,既然您说您希望它打印3
,请记住poll()
删除第一个元素,而不是最后一个元素。如果要删除最后一个,可以调用pollLast()
而不是poll()
.
推荐阅读
- c# - 使用 c# 字符串生成器将数据写入 csv 文件,仅用逗号分隔字段
- python - 熊猫遇到麻烦
- django - 如何在 django 模型之间创建关系
- c# - 没有核心身份的 ASP.NET Core 3.1 Web API 社交登录
- python - Pandas 是否对单索引数据帧使用散列,对多索引数据帧使用二进制搜索?
- c# - NLOG:创建同一类的多个实例将日志写入同一文件
- rest - 在 REST API 中发布具有关联文件资源的资源
- python - 对两个条件使用 find_elements_by_xpath 在 Python 中使用 OR 来抓取 src
- vim - How to set vi/vim on ubuntu to default to allowing pasting from clipboard using ctl-shift-c/v
- android - 如何使用 Kotlin 从 for 循环中打印特定数字