Java 从第二个字符串列表中存在的字符串列表中删除所有项目

Java 从第二个字符串列表中存在的字符串列表中删除所有项目,java,Java,我将在一系列PDF上执行一些基本的NLP,在将单词列表输出到CSV之前,我想从PDF中删除所谓的“停止单词”。我创建了一个包含停止词和PDF中的词的数组列表,并尝试使用removeAll。我在removeAll行的thread main中得到一个无用的错误-异常 public class ReadingText { public static void main(String args[]) throws IOException { String stopList = "i,me

我将在一系列PDF上执行一些基本的NLP,在将单词列表输出到CSV之前,我想从PDF中删除所谓的“停止单词”。我创建了一个包含停止词和PDF中的词的数组列表,并尝试使用removeAll。我在removeAll行的thread main中得到一个无用的错误-
异常

public class ReadingText {

public static void main(String args[]) throws IOException {
  String stopList = "i,me,my,...";
  
  String[] stopList1 = stopList.split(",");
  List<String> stopList2 = Arrays.asList(stopList1);
  
  File file = new File("C:/Users/Documents/Walmart_2020_Annual_Report.pdf");
  PDDocument document = PDDocument.load(file);
  PDFTextStripper pdfStripper = new PDFTextStripper();
  String text = pdfStripper.getText(document);
  text = text.replace(",", "");
  text = text.trim().replaceAll(" +", " ");
  text = text.replace(" ", ",");
  
  String[] text2 = text.split(",");
  
  List<String> wordList = Arrays.asList(text2);
  
  wordList.removeAll(stopList2);
  
  System.out.println(wordList.size());
公共类ReadingText{
公共静态void main(字符串args[])引发IOException{
字符串stopList=“i,me,my,…”;
字符串[]stopList1=stopList.split(“,”);
List stopList2=Arrays.asList(stopList1);
File File=新文件(“C:/Users/Documents/Walmart_2020_Annual_Report.pdf”);
PDDocument document=PDDocument.load(文件);
PDFTextStripper pdfStripper=新的PDFTextStripper();
String text=pdfStripper.getText(文档);
text=text.replace(“,”和“”);
text=text.trim().replaceAll(“+”,”);
text=text.replace(“,”,”);
字符串[]text2=text.split(“,”);
List wordList=Arrays.asList(text2);
单词列表.removeAll(停止列表2);
System.out.println(wordList.size());
} }
Arrays.asList()
返回一个列表,如果您试图更改其大小,该列表将引发异常

要从中创建可变列表,请执行以下操作:

wordList = new ArrayList<>(wordList);
wordList=newarraylist(wordList);

您得到的只是“主线程中的异常”?不是一个特定的异常,或者包含的错误消息?嗯,有点。您不能添加或删除它,但您可以更改它(它会很好地排序)。