package 截取字符窜;
import java.util.HashMap;
import java.util.Map;
public class StringDemo {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Map<Character, Integer> map = new HashMap<Character, Integer>();
String str = "abcdekka27qoq";
char[] c = str.toCharArray();
for (char d : c) {
Integer number = map.get(d);
if(number==null){
map.put(d, 1);
}else{
map.put(d,number+1);
}
}
System.out.println(map);
StringBuilder sb= new StringBuilder();
for (Map.Entry<Character, Integer> entry : map.entrySet()) {
sb.append(entry.getKey()).append("(").append(entry.getValue()).append(")");
}
System.out.println(sb.toString());
}
}
|