小编Eri*_*tov的帖子

如何使用字符串过滤我的列表?

有人可以解释我为什么我不能在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)

java collections java-stream

2
推荐指数
1
解决办法
79
查看次数

标签 统计

collections ×1

java ×1

java-stream ×1