日期:2014-05-20  浏览次数:20634 次

改个小错
Java code
package holding;

import static net.mindview.util.Print.print;

import java.util.HashMap;

import typeinfo.pets.Person;
import typeinfo.pets.Pet;

public class KeepCount extends HashMap
{
    static KeepCount kc=new KeepCount();
    public void add()
    {
        this.put("good","99.9" );
        this.put("bad","10" );
        this.put("soso","70" );
        this.put("good","90" );
        this.put("good","86" );
        this.put("bad","50" );
        this.put("soso","60" );
        this.put("soso","84" );
        this.put("good","99" );
        this.put("bad","40" );
        this.put("bad","56" );
        this.put("soso","71" );
        this.put("good","87" );
        this.put("bad","51" );
        this.put("soso","65" );
        this.put("good","100" );
    }
    public static void main(String[] args)
    {
        kc.add();
        System.out.println(kc);
        for(Object person : kc.keySet()) {
              print(person);
              for(Object pet : kc.get(person))  //这行错了,说什么不能迭代什么的
                print("    " + pet);
            }
        
    }

}


------解决方案--------------------
for(Object person : kc.keySet()) {//kc.keySet()对kc这个map的key组成的list进行迭代
print(person);//person是其中的一个key
for(Object pet : kc.get(person)) //kc.get(person)是kc中key为person所对应的map值,他就是一个value,所以不能迭代
print(" " + pet);
}