急需,我是初学Java的菜鸟,大家帮忙看一下下面这个有关集合的问题(打印每个字母出现的次数),怎么运行后没结果出现??
public class Demo01{public static void main(String[] args){
String[] str={"a","b","x","c","v","a","s"};
TreeMap<String, Integer> tm=new TreeMap<String,Integer>();
Set<Map.Entry<String , Integer>> set=tm.entrySet();
Iterator<Map.Entry<String ,Integer>> iterator=set.iterator();
for (int i = 0; i < str.length; i++) {
if(!(tm.containsKey(str[i]))){
tm.put(str[i],1);
}else{
Integer value=tm.get(str[i]);
tm.put(str[i], value++);
}
}
while(iterator.hasNext()){
Map.Entry<String, Integer> me=iterator.next();
String name=me.getKey();
Integer time =me.getValue();
System.out.println(name+(time));
}
}
}