class Station{
String stationName;
String stationType;
List<Station> connectedStation;
public Station(String v)
{
nodeNumber = v;
connectedStation = new LinkedList<Edge>();
}
}
class Edge{
Station dest;
public Edge(Station dest)
{
destination = dest;
}
}
class Graph{
HashMap<String, Station> stationRoutes;
.....
public String toString() {
StringBuilder builder = new StringBuilder();
Iterator<String> sta = stationRoutes.keySet().iterator();
Station v;
while(sta.hasNext()) {
String currentStation = sta.next();
List<String> connectedStations = v.connectStation.get(currentStation); // I get error here
builder.append(currentStation);
builder.append(" --> ");
builder.append(connectedStations);
builder.append('\n');
}
return builder.toString();
}
}
该程序所做的是列出每个特定电台所连接的电台。我想打印出每个特定电台所连接的所有电台。
如何打印List connectedStation中的特定值(电台)的所有元素。
我得到的错误是:
java.util.List中的get(int)不能应用于(java.lang.String)
列出connectedStations = v.connectedStation.get(currentStation);