recuperer un LinkedHashMap
Bonjour,
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
class Fmin {
LinkedHashMap<Integer, ArrayList<String>> arbre;
public LinkedHashMap<Integer, ArrayList<String>> FaireLesNiveaux(
ArrayList<String> list, int n) {
ArrayList<String> vecteur = new ArrayList<String>();
for (int i = 0; i < (n + 1); i++) {
for (int j = 0; j < list.size(); j++) {
String eltList = list.get(j);
int compteur = 0;
for (int k = 0; k < eltList.length(); k++) {
if (eltList.charAt(k) == '1')
compteur++;
}
if (compteur == i)
vecteur.add(eltList);
}
arbre = new LinkedHashMap<Integer, ArrayList<String>>();
arbre.put(i, vecteur);
System.out.println("niveau: " + arbre);
vecteur.clear();
}
return arbre;
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
public static void main(String[] args) {
ArrayList<String> elementGraphe = new ArrayList<String>(4);
LinkedHashMap<Integer, ArrayList<String>> arbre = new LinkedHashMap<Integer, ArrayList<String>>();
Fmin fm = new Fmin();
elementGraphe.add("0001");
elementGraphe.add("0110");
elementGraphe.add("1111");
arbre = fm.FaireLesNiveaux(elementGraphe, z);
for(int i=0; i<arbre.size; i++){
System.out.println("arbre"+ arbre.get(i));
}
} |
Resultat
Code:
1 2 3 4 5 6
|
{1=[]}
{2=[]}
{3=[]}
je ne comprends pas pkoi, les cles s'affiche, et les valeurs ne s'affichent pas dans le main
Alors que System.out.println dans la methode FaireLesNiveaux affiche les resultats |