How to return the value of a HashMap

This question already has an answer here:

  • Iterate through a HashMap [duplicate] 7 answers

  •  int total =teamPlayers.get(TeamType.TEAM_ONE).size() + teamPlayers.get(TeamType.TEAM_TWO).size()
    

    should work. Instead of referencing your old post can you post your current code? hard to know what changes youve made and what suggestions you took from the last post.

    updated answer for iterating through every entry in your TeamType enum:

    int total = 0;
    for(TeamType type : TeamType.values()){
        total += teamPlayers.get(type).size();
    }
    

    so the for each loop will iterate through each entry in your enum, and total will accumulate the number of players for each team

    链接地址: http://www.djcxy.com/p/17992.html

    上一篇: 通过HashMap循环

    下一篇: 如何返回一个HashMap的值