[Java] 纯文本查看 复制代码 import java.util.TreeMap;
/**
*
* @author AnCheng
*
*/
public class Test {
public static void main(String[] args) {
TreeMap<String, Integer> map = new TreeMap<>();
String str = "abcdekka27qoq";
for (int i = 0; i < str.length(); i++) {
String s = str.charAt(i) + "";
if (s.matches("[a-zA-Z]")) {
map.put(s, map.containsKey(s) ? map.get(s) + 1 : 1);
}
}
for (String key : map.keySet()) {
int value = map.get(key);
System.out.print(key + "(" + value + ")");
}
}
}
|