package com.lemon.json;

import java.util.HashMap;

/**
 * @program: Lemon
 * @description:
 * @author: ray
 * @create: 2022-09-23 10:53
 **/
public class StringDemo {
    public static void main(String[] args) {
        /*
         * 题目：有字符串String str="0AAA0BbC1ccc1D23ddd444"，分别统计每个字符出现的次数
         * 结果：最终输出A: B: C: D: 1: 2: 3: 4:
         * */
        String str = "0AAA0BbC1ccc1D23ddd444";
        char[] charArray = str.toCharArray();
        HashMap<Character, Integer> map = new HashMap<>();
        for (char c : charArray) {
            // 判断是否包含指定的键名c，
            if (map.containsKey(c)) {
                map.put(c, map.get(c) + 1);
            } else {
                // 不包含key，第一次存map
                map.put(c, 1);
            }
        }
        System.out.println(map);
    }
}
