如何在CSV文件的字符串中检查相应的单词


CSVParser parser = new CSVParserBuilder().withSeparator(';').build();
CSVReader csvReader = new CSVReaderBuilder(filereader).withCSVParser(parser).withSkipLines(1).build();
List<String[]> allData = csvReader.readAll();
String studentName = "Alice, Bob";
String[] words = studentName.split(",");
List<String> names = new ArrayList<>();
for(String[]row:allData){ // goes through the csv file
for(String word:words){ // goes through String names
if(row[3].contains(word)){
names.add(row[4]);
}
}
}

问题是for循环只通过CSV文件来检查";Alice";,并且不检查";Bob";,因此Bob没有被添加到列表中,我该如何解决?

row[3]=命名

row[4]=学校

@xerx593发现了错误,这解决了它:

String[] words = studentName.split(", ");

是一个拼写错误。

@xerx593发现了错误,这解决了它:

String[] words = studentName.split(", ");

最新更新