【发布时间】:2023-04-06 12:54:01
【问题描述】:
我正在尝试从推文中删除停用词,我首先添加标记,然后循环它们以查看它们是否与停用词集中的单词匹配,如果是,则删除它们。我得到一个 Java ConcurrentModificationErorr。这是一个sn-p。
while ((line = br.readLine()) != null) {
//store tweet splits
LinkedHashSet<String> tweets = new LinkedHashSet<String>();
//We need to extract tweet and their constituent words
String [] tweet = line.split(",");
String input =tweet[1];
String [] constituent = input.split(" ");
//add all tokens in set
for (String a : constituent) {
tweets.add(a.trim());
}
System.out.println("Before: "+tweets);
//replace stopword
for (String word : tweets) {
if (stopwords.contains(word)) {
tweets.remove(word);
}
}
System.out.println("After: "+tweets);
//System.out.println("Tweet: "+sb.toString());
【问题讨论】:
-
你得到的不是 ConcurrentModificationErorr(原文如此)。这是一个ConcurrentModificationException。只要在这里搜索 ConcurrentModificationException 就会引出许多类似的问题。
-
我使用重复的 Set 解决了它。检查我的答案。
标签: java