Mit dem keySet () - Methode in HashMap

Habe ich eine Methode, die geht durch die möglichen Zustände in einem board, und speichert Sie in eine HashMap

void up(String str){
  int a = str.indexOf("0");
  if(a>2){
   String s = str.substring(0,a-3)+"0"+str.substring(a-2,a)+str.charAt(a-3)+str.substring(a+1);
   add(s,map.get(str)+1);
   if(s.equals("123456780")) {
    System.out.println("The solution is on the level  "+map.get(s)+" of the tree");

        //If I get here, I need to know the keys on the map
       //How can I store them and Iterate through them using 
      //map.keySet()?

   }
  }

}

Ich bin interessiert in der Gruppe von Tasten. Was sollte ich tun, um drucken Sie alle?

HashSet t = map.keySet() abgelehnt wird vom compiler sowie

LinkedHashSet t = map.keySet()

InformationsquelleAutor andandandand | 2009-12-11

Schreibe einen Kommentar