0
Map<Integer, Map<String, String>> movie = new HashMap<Integer,Map<String, String>>();
Map<String,String> sub = new HashMap<String,String>();

I'm doing this to populate and trying to iterate it:

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);


            }

The problem I'm reaching is with the inner "for". It is getting all the "sub" Map values when I'm only need the pair (K,V) referenced by the outer Map key values. What is the correct way to iterate this Map inside a Map? How can I a reach an specific (K,V) from the inner Map using the key of the outer Map?

Thanks!

Martin Revert
  • 3,242
  • 2
  • 30
  • 33

1 Answers1

0

What you are trying to achieve is not very clear. But the problem probably is in the way you populate the map. You use the same sub for all the keys hence they all point to that same map which contains all the records. You should probably assign a new HashMap<String, String>() to sub every time you increment movieIndex.

But if you do that, based on your code sample, each key (movieindex) will point to a map that contains only one entry.

assylias
  • 321,522
  • 82
  • 660
  • 783