记录一下flatMap的用法
个人理解是将流中的流合并
@Data
@AllArgsConstructor
@NoArgsConstructor
public class WhiteIp {
//id
private Integer id;
//域名
private String domain;
//ip,多个用;分隔
private String ipaddress;
public static void main(String[] args) {
WhiteIp w1 = new WhiteIp(1,"127.0.0.1","127.0.0.1;localhost");
WhiteIp w2 = new WhiteIp(2,"www.baidu.com","192.123.123.1;192.111.111.1");
WhiteIp w3 = new WhiteIp(3,"www.hao123.com","localhost");
List<WhiteIp> list = new ArrayList<>();
list.add(w1);
list.add(w2);
list.add(w3);
List<String> result = list.stream()
.map(WhiteIp::getIpaddress)
.flatMap(v -> Arrays.stream(v.split(";")))
.collect(Collectors.toList());
System.out.println(result);
}
}
结果











![[附源码]java毕业设计全国人口普查管理系统论文](https://img-blog.csdnimg.cn/8f9fa5ecde164b7d9af2fd0eeb7b801b.png)




![[附源码]java毕业设计汽车租赁系统](https://img-blog.csdnimg.cn/39f586b0e2f545dd881690c6cdbb847c.png)



