【发布时间】:2011-02-09 01:31:22
【问题描述】:
HashMap selections = new HashMap<Integer, Float>();
如何获取所有 HashMap 中 Float 的第 3 个较小值的 Integer 键?
编辑 我为此使用HashMap
for (InflatedRunner runner : prices.getRunners()) {
for (InflatedMarketPrices.InflatedPrice price : runner.getLayPrices()) {
if (price.getDepth() == 1) {
selections.put(new Integer(runner.getSelectionId()), new Float(price.getPrice()));
}
}
}
我需要深度为 1 的第三个较小价格的跑步者
也许我应该以另一种方式实现它?
【问题讨论】:
-
如果您告诉我们更多关于
selections是什么以及您如何使用此查询的信息,我们或许可以为您推荐更好的数据结构。 -
每个跑步者可以有多个深度为 1 的价格吗?因为如果可能的话,那么您现在的
selections将只为每个runner保留其中一个。 -
不,只有 3 个深度.. 1、2 和 3
-
但是跑步者的
getLayPrices在深度 1 处返回超过 1 个价格吗? -
不不,只是且始终各有 1 个