【发布时间】:2020-05-06 20:11:30
【问题描述】:
我有一些代码:
Collection<MyGraph.MyVertex> vertCollection = graph.getVertices();
其中 getVertices 是 JUNG 包的一部分,其定义如下:
public interface Hypergraph<V, E> {
Collection<E> getEdges();
Collection<V> getVertices();
...
...
}
> If I print out the collection I may get something like [v1,v2,v4,v3]
> and on another run something like [v2,v3,v1,v4]
这让我每次都以随机顺序返回一个顶点列表。因此,我在代码其他地方的结果是不可重复的,而且很难追踪。
我希望每次都以相同的方式恢复元素的顺序。我目前的猜测是我必须将集合转换为某种保留顺序的数据结构,然后对其进行排序,以便结果是可重复的,但有没有更好的方法来做到这一点? (我不确定从集合转换为数组之类的其他东西是否会破坏其他地方的代码,因为我是集合的新手)。任何帮助都会很棒!
【问题讨论】:
标签: java data-structures graph collections jung