別の HashMap を含む HashMap があります。最初の HashMap を反復処理し、そこから Key 値を使用したいと考えています。次に、最初の HashMap を反復処理するときに、2 番目の HashMap を反復処理する内部ループを開始して、すべての値を取得します。
これまでの問題は、イテレータからキーを取得する方法がわからないことです。
HashMap<String, HashMap<Integer, String>> subitems = myHashMap.get("mainitem1");
Collection c = subitems.values();
Iterator itr = c.iterator();
while(itr.hasNext())
{
// Get key somehow? itr.getKey() ???
// contains the sub items
HashMap productitem = (HashMap)itr.next();
}
私が取得するデータsubitems
は次のとおりです。
{Item1{0=sub1, 1=sub2}, Item2{0=sub3, 1=sub4}}
次に、while ループproductitem
に「サブ項目」が含まれます。しかし、キー値「Item1」と「Item2」をどこから取得できるかわかりません。
どうすればそれらを入手できますか?