Process data from a HashMap in Java

0

If I have the following hashMap in Java

Key - {value}
 a    {1,2,3,4}
 b    {2,3,4,5}
 c    {1,2,3,4}
 d    {3,4,5,6}

I would like to obtain the following result by console:

a->2
b->1
d->1

How do I implement this processing of my hashMap ?

Patterns is a HashMap , ResultadoFinal is a ArrayList is where I have the info to try.

for (Entry<String, ArrayList<String>> ee : m.entrySet()) {
    String key = m.getKey();
    List<String> values = m.getValue();
    comparar(Patrons,key,values,ResultadoFinal);
}

private static void comparar(HashMap<String, ArrayList<String>> rrr, String peti,List<String> cod,ArrayList<String> aaa) {
    // TODO Auto-generated method stub

    int cantidad = 0;

    if (rrr.isEmpty()) {
        rrr.put(peti, (ArrayList<String>) cod);
    } 
    else {
        for (Entry<String, ArrayList<String>> aa : rrr.entrySet()) {
            List<String> values = aa.getValue();
            if(values == cod){
            cantidad++;
            peti = peti + " " + cantidad;
            //System.out.println(peti);
            aaa.add(peti);
        }
    }
    else {
        rrr.put(peti, (ArrayList<String>) cod);             
    }
}

for (Entry<String, ArrayList<String>> oo : rrr.entrySet()) {    
    String Solanos = oo.getKey();
    Solanos= Solanos + " 1";
    aaa.add(Solanos); */
}
    
asked by pastagana 04.01.2017 в 18:01
source

0 answers