【问题标题】:Selecting specific elements and printing the number of them in a Queue选择特定元素并在队列中打印它们的数量
【发布时间】:2013-06-13 13:33:26
【问题描述】:

我创建了一个队列(通用),每个元素都有一个字符串和时间戳值。现在我正在尝试选择时间戳超过一小时的元素并打印出它们的总和和其他操作。我查看了 java.util.Queue 的方法,但没有一个具有这种能力。

请问我该怎么办?

【问题讨论】:

  • 你有代码吗?你试过什么?

标签: java timestamp queue


【解决方案1】:

contains() 方法不起作用?那么你的元素需要正确编码equalsTo()hashCode()

【讨论】:

  • 感谢您的所有意见。我想出了如何做我想做的事
【解决方案2】:

我想你可以试试 PriorityQueue

Queue<Type> priorityQueue = new PriorityQueue<Type>(20, new Comparator<Type>() {

  public int compare(Type o1, Type o2) {
    //Do compare based in criterio for sorting queue by timestamps
  }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-22
    • 2021-07-20
    相关资源
    最近更新 更多