遍历list集合按照其中一个属性分类放入Map中

for (AppServerInfo appServerInfo : serverInfoList) {
	String envIp = appServerInfo.getEnvIp();
	if (serverMap.keySet().contains(envIp)) {
		    serverMap.get(envIp).add(appServerInfo);
		}else {
		    List<AppServerInfo> tempServerList =  new ArrayList<>();
		    tempServerList.add(appServerInfo);
		    serverMap.put(envIp, tempServerList);
		}
	}

 

    原文作者:sayok_why
    原文地址: https://blog.csdn.net/sayoko06/article/details/81099632
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞