我需要一些帮助在Java中创建动态顶点的帮助。我从MySQL数据库获取数据,到目前为止,我有这样的:Java - 动态创建顶点
String query = "SELECT * FROM coordinates";
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
while (rs.next())
{
int id = rs.getInt("id");
String vert = Integer.toString(id);
//Which approach will work?
Vertex vert = new Vertex(vert);
}
st.close();
这是顶点应该的样子:
Vertex 1 = new Vertex("1");
Vertex 2 = new Vertex("2");
Vertex 5 = new Vertex("5");
Vertex 8 = new Vertex("8");
//...and so on...
编辑
所以我这样做,是可以吗?:
Map<String, Vertex> map = new HashMap<>();
while (rs.next()){
int id = rs.getInt("id");
String id_vertex = Integer.toString(id);
map.put("X" + id, new Vertex(id_vertex));
}
但现在我必须创建我的顶点权利?
最后我会还需要创建的边缘,因为我需要这样的Dijkstra算法Algorithm..so我创造的边缘是这样的:
X151.adjacencies = new Edge[]{new Edge(X3957,261),new Edge(X3589,194)};
的主要问题是,我是越来越这错误:The code of method main(String[]) is exceeding the 65535 bytes limit
我做对了吗,这会解决我的问题,还是我的想法完全错误?
一个'List'或'Map'应该是你去的地方。但是,在回答你的问题时,你宁愿选择“地图” – SomeJavaGuy