java命令:将字符串转换成单个字符串,再转成集合打印出来。
public class Test {
public static void main(String[] args) {
String str="HelloWorld";
Map<Character, Integer> jilu=new HashMap<Character, Integer>();
char[] arrstr=str.toCharArray();
for(char zf:arrstr) {
if(jilu.containsKey(zf)) {
int n=jilu.get(zf);
jilu.put(zf, n+1);
}else {
jilu.put(zf, 1);
}
}
Set<Entry<Character, Integer>> en=jilu.entrySet();
for(Entry<Character, Integer> ens:en) {
System.out.println(ens.getKey()+":"+ens.getValue());
}
}
}