正则表达式统计字符串出现次数

xiaoxiao2026-08-08  8

public static void main(String[] args) { String str = "中国,美国,日本,朝鲜,中国,中国,美国,越南"; String reg = "中国"; Pattern p = Pattern.compile(reg); Matcher m = p.matcher(str); int i = 0; while(m.find()) { i++; } System.out.println(i); }

 

转载请注明原文地址: https://www.6miu.com/read-5050882.html

最新回复(0)