满意答案
import java.util.*;
public class Test {
public Map fun(String string){
Map map = new HashMap();
for (int i = 0; i < string.length(); i++) {
char c = string.charAt(i);
if(null == map.get(c))map.put(c, 1);
else {
int length = map.get(c)+1;
map.put(c, length);
}
}
return map;
}
public static void main(String[] args) {
Test test = new Test();
Map map = test.fun("xsakjnakbashkjnxajkvhkdcnajkxhsjkac");
for (Entry entry : map.entrySet()) {
System.out.println(entry.getKey()+":"+entry.getValue());
}
}
}
10分享举报