如何获取队列中的第 n 个项目? [英] How do I get the nth item in a Queue?

查看:37
本文介绍了如何获取队列中的第 n 个项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有许多队列和优先级队列.我想轻松访问这些队列中的第 n 个项目,但看不到使用 API 的简单方法.

I have a number of queues and priority queues in my application. I would like to easily access the nth items in these queues, but don't see an easy way to do that using the API.

我想我可以创建一个 Iterator 并迭代到第 n 个元素或使用 toArray()[index],但似乎应该有更简单的方法.

I guess I could create an Iterator and iterate to the nth element or use toArray()[index], but it seems like there should be an easier way.

我错过了什么吗?

推荐答案

我错过了什么吗?

Am I missing something?

是的 - 通过索引访问元素不是队列概念的一部分.

Yes - the fact that accessing elements by index is not part of the concept of a queue.

如果你需要通过索引访问元素,你需要一个列表,而不是一个队列.

If you need to access elements by index, you want a list, not a qeue.

这篇关于如何获取队列中的第 n 个项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆