有人可以解释我为什么我不能在List by .stream()中过滤我的字符串.过滤器?我收到的只是未经过滤的字符串!我会很感激的.
public static void main(String[] args) throws FileNotFoundException {
List<Country> countries = CsvToBeanConverterCountry("country.csv");
countries
.stream().filter(s -> s.getName().contains("xx")).collect(Collectors.toList());
countries.forEach(s -> System.out.println(s.getName()));
}
private static List CsvToBeanConverterCountry(String csvFilename) throws FileNotFoundException {
CsvToBean csv = new CsvToBean();
CSVReader csvReader = new CSVReader(new FileReader(csvFilename), ';', '"', 1);
List list = csv.parse(setColumMappingCountry(), csvReader);
return list;
}
private static ColumnPositionMappingStrategy setColumMappingCountry() {
ColumnPositionMappingStrategy strategy = new ColumnPositionMappingStrategy();
strategy.setType(Country.class);
String[] columns = new String[]{"country_id", "city_id", "name"};
strategy.setColumnMapping(columns);
return strategy;
}
}
Run Code Online (Sandbox Code Playgroud)