package com.supervision.util; import java.util.Arrays; /** * @Author:longbao * @Date:2024/11/1 13:52 * @Description: */ public class StringChartUtil { /** * 字符串中某个字符出现的次数 * @param str 源字符串 * @param targetChar 查找字符 * @return 出现次数 */ public static int countChar(String str, char targetChar) { return (int) Arrays.stream(str.split("")) .filter(s -> s.charAt(0) == targetChar) .count(); } }