public static void test(String str){
Map map = new HashMap();
for(int i = 0; i < str.length(); i++){
String ch = str.charAt(i) + "";
Object och = map.get(ch);
if(och == null){
map.put(ch, new Integer(1));
}else{
map.put(ch, new Integer(((Integer)och).intValue()+ 1));
}
}
Iterator it = map.keySet().iterator();
System.out.println("字符串的总数是:" + str.length());
System.out.println("/的数量是 " + map.get("/"));
while(it.hasNext()){
// String key = (String)it.next();
System.out.println("字母 " + key + " 的数量是 " + map.get("/"));
}
}
string,hashmap
最新推荐文章于 2024-01-10 16:45:16 发布