在地图上而不是列表上迭代

问题描述 投票:-1回答:2

我呈现结果的代码如下:

    private void presentResult(List<Long> result) {
    if(result.size() == 0) {
        System.out.println("No matching values for the provided query.");
    }       
    for(String s : result) {
        System.out.println(s);
    }
}

但是我想返回一个哈希表而不是列表,所以我希望它像这样:

    private void presentResult(Map<LocalDate, Long> result) {
    if(result.size() == 0) {
        System.out.println("No matching values for the provided query.");
    }       
    for(Map<LocalDate, Long> s : result) {
        System.out.println(s);
    }
}

但随后出现此错误:“只能迭代数组或java.lang.Iterable的实例”如何解决?

java list hashmap converters
2个回答
0
投票

0
投票

0
投票
© www.soinside.com 2019 - 2024. All rights reserved.