This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
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();
}