Java 8 要映射的Java8流

Java 8 要映射的Java8流,java-8,maps,java-stream,Java 8,Maps,Java Stream,我想将以下内容转换为功能程序。请帮助串列以下代码 Map <String, TreeSet<Double>> cusipMap = new HashMap<>(); String[] key = new String[1]; try { Files.lines(Paths.get("C:\\CUSIP.txt")). forEach(l -> {

我想将以下内容转换为功能程序。请帮助串列以下代码

Map <String, TreeSet<Double>> cusipMap = new HashMap<>();
        String[] key = new String[1];
        try {
            Files.lines(Paths.get("C:\\CUSIP.txt")).
            forEach(l -> {
                if (isCUSIP(l)) {
                    if (cusipMap.get(l) == null )
                        cusipMap.put(l, new TreeSet<Double>());
                    key[0] = l;
                } else {
                    cusipMap.get(key[0]).add(Double.valueOf(l));

                }
            });
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
Map cusipMap=newhashmap();
字符串[]键=新字符串[1];
试一试{
Files.line(path.get(“C:\\CUSIP.txt”))。
forEach(l->{
if(isCUSIP(l)){
if(cusipMap.get(l)==null)
cusipMap.put(l,新树集());
键[0]=l;
}否则{
cusipMap.get(键[0]).add(Double.valueOf(l));
}
});
}捕获(IOE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
试试这个

 try {
     Map<String, TreeSet<Double>> result = Files.lines(Paths.get("C:\\CUSIP.txt"))
    .collect(Collectors.groupingBy(Function.identity(), Collector.of(                   
TreeSet::new,               
(TreeSet<Double> tree, String s) -> {tree.add(Double.valueOf(s));},                 
(TreeSet<Double> tree, TreeSet<Double> s) -> {tree.addAll(s); return tree;}
                    )));        
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
试试看{
映射结果=Files.lines(path.get(“C:\\CUSIP.txt”))
.collect(Collector.groupingBy(Function.identity(),Collector.of(
树集::新,
(TreeSet树,字符串s)->{tree.add(Double.valueOf(s));},
(树集树,树集s)->{tree.addAll(s);返回树;}
)));        
}捕获(IOE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}

请显示您的尝试,并显示您遇到的具体问题。