【发布时间】:2014-11-22 03:33:35
【问题描述】:
我想遍历一个哈希图。我知道我可以轻松使用 entrySet。但问题是我想一次访问两个元素。
示例:
HasHMap<Integer,Point> myMap = new HashMap<Integer,Point>();
//I add some points to the map where integer is the id of that point
我希望能够同时访问两个元素,这样我就可以使用 Graphics 的 drawLine 方法。
我不确定是否有办法。
注意:我使用的是 hashmap,因为它的 id 很容易找到任何点,因为我的地图的多边形是由 id 列表组成的。
【问题讨论】:
-
每对两点?还是只有两个具体点?您可以多次致电
myMap.get。 -
是的,遍历每一对两点。 @LouisWasserman