给出一个字符串,找出相同字母的次数

阅读更多
importjava.util.HashMap;
02
03
04 publicclassTestArray {
05
06 /**
07 *
08 * @param args
09 */
10 publicstaticvoidmain(String[] args) {
11 String inputstr ="abcbssssssssssss";
12 char[] array_input = inputstr.toCharArray();
13 HashMap map =newHashMap();
14 for(inti=0;i
15 Character row = array_input[i];
16 //System.out.println(row);
17 if(map.containsKey(row)){//包含key value值加1
18 Integer count = map.get(array_input[i])+1;
19 map.remove(row);
20 map.put(row, count);
21 }else{
22 map.put(row,1);
23 }
24 }
25 System.out.println(map);
26
27 }
28
29
30 }

你可能感兴趣的:(给出一个字符串,找出相同字母的次数)