如何使用for循环浏览地图

时间:2019-12-18 13:38:22

标签: java

我从数据库中获得了一张地图,该地图如下:

{70007564=[PensionMediumView : {mtBrutPension=10480.32, quartierId=LS, typePensionId=21, destinataireBulletin=1, txPensionRetenu=40.5,}]}

如果尝试循环查找“ typePensionId = 21”(键号3),则尝试显示错误消息。 我使用了以下代码:

final Long idBeneficiaire = context.getIdPersonne();
        final Map<Long, List<PensionMediumView>> mapPensionsBeneficiaire = this.pensionBusinessApplicatif
            .recupererPensionsActivesParBeneficiaires(Arrays.asList(idBeneficiaire), context.getIdentificationContext());
    for (final Map.Entry<Long, List<PensionMediumView>> entry : mapPensionsBeneficiaire.entrySet()){
......
}

如果我发现“ typePensionId = 21”,如何显示错误消息

1 个答案:

答案 0 :(得分:0)

从您的问题中我相信这是您正在寻找的东西。正如我在if语句中所评论的那样,我不确定如何通过查看您的示例来获取养老金类型ID。希望这会有所帮助。

final Long idBeneficiaire = context.getIdPersonne();
final Map<Long, List<PensionMediumView>> mapPensionsBeneficiaire = this.pensionBusinessApplicatif
    .recupererPensionsActivesParBeneficiaires(
    Arrays.asList(idBeneficiaire),
    context.getIdentificationContext());
for (final Map.Entry<Long, List<PensionMediumView>> entry : mapPensionsBeneficiaire.entrySet()){
    for(PensionMediumView pension : enter.getValue()) {
        // I wasn't sure of how to get the pension id from your example
        // So just replace this with example getter with however you get your pension ID
        if(pension.typePensionId() == 21) {
            System.out.println("Error!");
            break; // This will stop the loop, 
            // if you want the loop to continue, don't use this
        }
    }
}