[英]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我期待它打印 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
有人可以告诉我如何从轮询元素中检索列表值我需要每个轮询元素中的所有三个值
The element returned with the method queue.poll()
is a Array<IntArray>
, not an IntArray
.使用
queue.poll()
方法返回的元素是Array<IntArray>
,而不是IntArray
。 When you call queue.poll()[0]
you are getting the first element of that Array<IntArray>
, so an IntArray
.当您调用
queue.poll()[0]
您将获得该Array<IntArray>
的第一个元素,因此是IntArray
。 If you want to get the first element of the IntArray
, you should call queue.poll()[0][0]
:如果你想获取
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())
Furthermore, since you said you expected it to print 3
, remember that poll()
removes the first element, not the last one.此外,由于您说您希望它打印
3
,请记住poll()
删除第一个元素,而不是最后一个。 If you want to remove the last one, you can call pollLast()
instead of poll()
.如果你想删除最后一个,你可以调用
pollLast()
而不是poll()
。
Seems like i was putting an Array of Array in the queue好像我在队列中放了一个数组数组
the correct code should be正确的代码应该是
var queue = LinkedList<Array<Int>>()
queue.add(arrayOf(1,2,0))
queue.add(arrayOf(3,4,5))
Log.d("alpha",queue.poll()[0].toString())
Now I am getting 1 as expected现在我按预期得到 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.