Java HashMap: How to get a key and value by index?

后端 未结 10 1394
鱼传尺愫
鱼传尺愫 2020-12-28 12:54

I am trying to use a HashMap to map a unique string to a string ArrayList like this:

HashMap>

Basical

10条回答
  •  南笙
    南笙 (楼主)
    2020-12-28 13:20

    If you don't care about the actual key, a concise way to iterate over all the Map's values would be to use its values() method

    Map> myMap;
    
    for ( List stringList : myMap.values() ) {
        for ( String myString : stringList ) {
            // process the string here
        }
    }
    

    The values() method is part of the Map interface and returns a Collection view of the values in the map.

提交回复
热议问题