import java.util.HashMap; |
02 |
03 |
04 | public class TestArray { |
05 |
06 |
/** |
07 |
* |
08 |
* @param args |
09 |
*/ |
10 |
public static void main(String[] args) { |
11 |
String inputstr = "abcbssssssssssss" ; |
12 |
char [] array_input = inputstr.toCharArray(); |
13 |
HashMap<Character,Integer> map = new HashMap<Character,Integer>(); |
14 |
for ( int i= 0 ;i<array_input.length;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 | } |