【发布时间】:2014-05-01 20:00:32
【问题描述】:
以下方法如何工作?
Pairs 是一个 LinkedHashMap,我只是不确定增强的 for 循环以及它如何与 hasmap 一起使用。即键集。
/**
* Finds all names in the initial input list that match phonetically with
* the supplied name
*
* @param phoneticName
* The name for which you want to find matches
* @return An ArrayList of all phonetically matching names
*/
public ArrayList<String> findMatchingNames(String phoneticName) {
ArrayList<String> matchedNames = new ArrayList<>();
for (String s : Pairs.keySet()) {
if (phoneticName.equals(Pairs.get(s))) {
matchedNames.add(s);
}
}
return matchedNames;
}
}
【问题讨论】:
-
增强的for循环适用于所有实现
java.lang.Iterable的实例
标签: java arraylist linkedhashmap