Map<Integer, Map<String, String>> movie = new HashMap<Integer,Map<String, String>>();
Map<String,String> sub = new HashMap<String,String>();
我这样做是为了填充并尝试迭代它:
Iterator<Element> releases = doc.select(
"div.pmovie > div.releases > div.release").iterator();
Iterator<Element> subt = doc.select(
"div.release-info > div.section > div.links > div > a")
.iterator();
int movindex = 1;
while (subt.hasNext()) {
Element rel = releases.next();
Element subti = subt.next();
release = rel.text();
Log.v("RELEASES", release);
subtitulo = subti.attr("href");
Log.v("SUBTITULO", subtitulo);
sub.put(release,subtitulo);
movie.put(movindex, sub);
movindex++;
}
for (Entry<Integer, Map<String,String>> entry : movie.entrySet()) {
key = entry.getKey();
sub = entry.getValue();
for (Entry<String,String> entrada : sub.entrySet()) {
subtitle = entrada.getKey();
ruta = entrada.getValue();
Log.v("SUB ITERATOR", key+" "+subtitle);
}
我遇到的问题是内在的“for”。当我只需要外部 Map 键值引用的对 (K,V) 时,它正在获取所有“子”映射值。在 Map 中迭代此 Map 的正确方法是什么?如何使用外部地图的键从内部地图到达特定的(K,V)?
谢谢!