public class CalculateChar {
public static void main(String[] args) {
//String s = charCount("abadcdffbaeba");
ArrayList<String> al = charCount("abadcdffbaeba");
System.out.println(al);
}
public static ArrayList<String> charCount(String str){
char[] chs = str.toCharArray();
TreeMap<Character,Integer> tm = new TreeMap<Character,Integer>();
int count = 0;
for(int x=0;x<chs.length;x++){
if((chs[x]>='a'&&chs[x]<='z') || (chs[x]>='A'&&chs[x]<='Z')){
Integer value = tm.get(chs[x]);
if(value!=null)
、 count++;
tm.put(chs[x], count);
count = 0;
}
}
System.out.println(tm);
}
我想先把这个字符串变成treeMap集合打印出来,哪里出什么问题了吗? |
|