有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

具有重复键的java SortedMap

我需要根据类的方法返回的浮点对自定义类(Face)的一些对象进行排序

我决定使用排序映射,但我意识到集合不会返回重复的键

这是我的代码:

sorted.clear();
for(Face f : face) {
  sorted.put(f.getFarthestDepth(), f);
}
//Code for printing entries of the sortedTree
for(Map.Entry entry : sorted.entrySet())
  print(entry.getKey() + " ");
println();

在我的渲染方法中,我有:

pushMatrix();
translate(center.x, center.y);
for(Map.Entry entry : sorted.entrySet()) {
  Face f = (Face)entry.getValue();
  beginShape();
  fill(255);
  for (Vertex v : f.vertex) {
    vertex(v.x, v.y);
  }
  endShape(CLOSE);
}  
popMatrix();

当我打印树映射的条目时,我只得到2个值,我需要得到6个具有相同键值的值

我正在使用Processing,但代码几乎与java相似

如何获取所有面对象


共 (1) 个答案

  1. # 1 楼答案

    使用带有自定义比较器的番石榴树形图。它保留重复关键点的对象列表