我正在尝试为每个具有特定关键字的列表项构建一个列表并增加一个计数器。我无法编译这个。为什么呢?
int count = 0;
String keyword = args[1];
Pattern p = Pattern.compile(keyword);
Matcher m = p.matcher(p);
/* For each paragraph in the document... */
for (XWPFParagraph paragraph : paragraphs) {
/* Add to List */
words.add(paragraph.getText());
System.out.println(paragraph);
/* Iterate keyword count */
while (m.find()) {
count++;
}
}
答案 0 :(得分:1)
问题可能就在这里
Matcher m = p.matcher(p);
参数应该是要搜索的文本
Matcher m = p.matcher(paragraph.getText());