【发布时间】:2014-03-14 21:44:08
【问题描述】:
我正在尝试编写一个方法,该方法将从我的 HashMap 中返回一个 ArrayList 字符串。
目前我有一个 HashMap,其中包含一个 String 作为标识符(键?),以及一个 String 类型的 List 包含与其关联的所有值。该程序旨在模拟火车/地铁导航工具,因此第一个 String 是车站名称,arraylist 是一系列显示所有连接车站的字符串。
这是我目前所拥有的,但目前无法编译。我知道还有其他几种方法正在起作用,所以我只放了最后一种我遇到困难的方法(getConnections)。
我在这方面非常新手,所以如果有人能指出我哪里出错了,我真的很感激。
public class MyNetwork implements Network {
Map<String, List<String>> stations = new HashMap<>();
@Override
public String[] getConnections(String fromStation) {
/**
* Get a list of all stations directly connected to a given station.
*
* @pre fromStation has been added to the network by the method
* addStation.
* @param fromStation
* @return A list of all the stations to which there is a direct
* connection from fromStation.
*/
ArrayList<String> Connections = new ArrayList<>();
Set<String> keys = stations.keySet();
for (String k : keys) {
String keyValue;
keyValue = (stations.get(fromStation));
}
return fromStation;
}
【问题讨论】:
标签: java string map arraylist hashmap