有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

函数式编程在Java 8中如何在不转换为数组的情况下检查流对象的内容?

Basically I have to do the following: 1)Read the CSV input file. 2)Filter the CSV data based on the blacklist. 3)Sort the input based on the country names in ascending order. 4)Print the records which are not blacklisted. The CSV file contains: id,country-short,country 1,AU,Australia 2,CN,China 3,AU,Australia 4,CN,China The blacklist file contains: AU JP And the desired output is 2,CN,China 4,CN,China

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamProcessing {
    public static void filterCsv(String fileName, String blacklistFile){


         try (Stream<String> stream1 = Files.lines(Paths.get(fileName))) {
             Stream<String> stream2 = Files.lines(Paths.get(blacklistFile));
             Optional<String> hasBlackList = stream1.filter(s->s.contains(stream2)).findFirst();
         } catch (IOException e) {
             e.printStackTrace();
         }
    }   



    public static void main(String args[])
    {
        StreamProcessing sp = new StreamProcessing();
        sp.filterCsv("Data.csv","blacklist.txt");
    }
}

我想从第一个流中删除第二个流中存在的条目,而不将其转换为数组


共 (0) 个答案