package Streams.Test3;import java.util.*;public class Client { public static void main(String[] args) { List<String> stringList = new ArrayList<>(); stringList.add("fileName=/home/sdf/test.pro"); stringList.add("ip=192.168.1.1"); stringList.add("port=12234"); Map<String,String> result =stringList.stream() .map((s)->{ Map<String,String> resultMap = new HashMap<>(); resultMap.put(s.split("=",2)[0],s.split("=",2)[1]); return resultMap ; }).reduce(new HashMap<>(),(x,y)->{ x.putAll(y); return x; }); result.forEach((k,v)->{ System.out.println(k+":"+v); }); }} 测试结果: port:12234 fileName:/home/sdf/test.pro ip:192.168.1.1 Process finished with exit code 0
贴个代码真难
Sign in to make a reply
用户6305896977