无法使用Map <string,string =“”> whichMap作为输入参数调用方法?</string,>

时间:2015-03-15 14:36:28

标签: java android

我在一个类中有2个哈希映射,称为 pathMap fileMap ,我需要从中提取某些值。这很简单 如果我有两个单独的方法,但我希望我可以将它们两者结合起来,但以下方法不起作用:

 Map<String, String> pathMap  = new LinkedHashMap<>();
 thisPath = thisMap.getSavedValues(item, pathMap);
 Map<String, String> fileMap  = new LinkedHashMap<>();
 thisFile = thisMap.getSavedValues(item, fileMap);

 ....
 public String getSavedValues(String key, Map<String, String> whichMap){
    Set<Map.Entry<String, String>> set = whichMap.entrySet();
    String hashKey = "", hashValue = "";
    for (Map.Entry<String, String> check : set) { //--- Iterate complete HashMap here --
        hashKey   = check.getKey();
        hashValue = check.getValue();
        if (hashKey.equals(key)) {
            break;
        }
    }
    return hashValue;
 }

有人可以帮忙吗?更具体地说,这是有效的:

 thisPath = thisMap.getPath(item);
 ....
 public String getPath(String key){
    Set<Map.Entry<String, String>> set = pathMap.entrySet();
    String hashKey = "", hashValue = "";
    for (Map.Entry<String, String> check : set) { //--- Iterate complete HashMap here --
        hashKey   = check.getKey();
        hashValue = check.getValue();
        if (hashKey.equals(key)) {
            break;
        }
    }
    return hashValue;
 }


 thisFile = thisMap.getFile(item);
 ....
 public String getFile(String key){
    Set<Map.Entry<String, String>> set = fileMap.entrySet();
    String hashKey = "", hashValue = "";
    for (Map.Entry<String, String> check : set) { //--- Iterate complete HashMap here --
        hashKey   = check.getKey();
        hashValue = check.getValue();
        if (hashKey.equals(key)) {
            break;
        }
    }
    return hashValue;
 }

我只想把两者结合在一起。

0 个答案:

没有答案