我有一个来自textArea.getText()的字符串。我也有一个textField,其中插入了一些用空格隔开的单词。我想在textArea中搜索插入的单词,计算每个单词的出现次数。对于插入的单个单词,我使用了类似的方法
public void findTheWord(String stringToCheck, String regexString) throws IOException {
int count = 0;
Pattern regexp = Pattern.compile(regexString);
Matcher matcher = regexp.matcher(stringToCheck);
while (matcher.find()) {
count++;
String matchString = matcher.group();
System.out.println(matchString);
}
System.out.println(count);
}