【发布时间】:2018-05-17 04:46:20
【问题描述】:
大家好,
我创建了一个简化程序来向您展示我愿意做什么。 这个想法是在每个顶点之间创建一条边。
类顶点:
public class Vertex {
private String sequence = new String();
public Vertex() {
}
public Vertex(String seq) {
this.sequence = seq;
}
@Override
public String toString() {
return this.sequence.toString();
}
}
类边缘:
public class Edge {
private Vertex source;
private Vertex destination;
private int weight;
public Edge() {
}
public Edge(Vertex source, Vertex destination, int weight) {
this.source = source;
this.destination = destination;
this.weight = weight;
}
}
召唤程序:
public class Example {
public static void main(String[] args) {
ArrayList <Vertex> listOfVertex = new ArrayList<>();
listOfVertex.add(new Vertex("One"));
listOfVertex.add(new Vertex("Two"));
listOfVertex.add(new Vertex("Three"));
ArrayList <Edge> listOfEdges = new ArrayList<>();
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i==j)
continue;
int weight = new Random().nextInt();
Edge edge = new Edge(listOfVertex.get(i), listOfVertex.get(j),weight);
listOfEdges.add(edge);
}
}
}
}
通常在这一步中边缘列表应该有
- 边 1:一二
- 边 2:一三
- 边缘 3:二一
- 边缘 4:二三
- 边 5:三一
- 边 6:三二
如何使用Java Stream 来使用多线程? 我一整天都在搜索以了解 Java 8 for stream 的语法,但这非常困难。
【问题讨论】:
-
"如何使用Java Stream来使用多线程?" - 做什么?
-
快速完成两个 for 循环,因为 1- 在我的实际程序中,我正在处理大量顶点,2 - Edge 的构建需要很长时间才能完成(重计算)。
标签: java multithreading arraylist java-8