[英]How to unpack a list in java to sublist
I got a list by the following code:我通过以下代码得到了一个列表:
ArrayList<String> single = new ArrayList<String>()
- [Document{{packetsLost=0,id=ssrc_1848956494_recv, timestamp=2019-07-11T07:18:42.923Z}}, Document{{packetsLost=10, timestamp=2019-07-11T07:20:43.413Z}}]
- [Document{{packetsLost=0, id=ssrc_1848956494_send, timestamp=2019-07-11T07:18:42.923Z}}, - Document{{packetsLost=10, timestamp=2019-07-11T07:20:43.413Z}}]
- [Document{{packetsLost=0,id=ssrc_929521404_recv, timestamp=2019-07-11T07:18:42.923Z}}, Document{{packetsLost=10, timestamp=2019-07-11T07:20:43.413Z}}]
- [Document{{packetsLost=0,id=ssrc_929521404_send, timestamp=2019-07-11T07:18:42.923Z}}, Document{{packetsLost=10, timestamp=2019-07-11T07:20:43.413Z}}]
I am new to java, how can I create sub-lists from the list retrieved, knowing that packet lost values in a list and timestamp in other list with a sign (id) like:我是java新手,如何从检索到的列表中创建子列表,知道数据包丢失了列表中的值和其他列表中带有符号(id)的时间戳,例如:
1- id=ssrc_1848956494_recv
[0 , 0]
[2019-07-11T07:18:42.923Z, 2019-07-11T07:20:43.413Z]
2- id=ssrc_1848956494_send
[0 , 0]
[2019-07-11T07:18:42.923Z, 2019-07-11T07:20:43.413Z]
3- id=ssrc_929521404_recv
[0 , 0]
[2019-07-11T07:18:42.923Z, 2019-07-11T07:20:43.413Z]
4- id=ssrc_929521404_send
[0 , 0]
[2019-07-11T07:18:42.923Z, 2019-07-11T07:20:43.413Z]
We can make use of streams here to generate the two lists:我们可以在这里使用流来生成两个列表:
List<String> packetsList = single.stream()
.map(x -> x.replaceAll(".*packetsLost=(\\d+).*", "$1"))
.collect(Collectors.toList());
List<String> timestampsList = single.stream()
.map(x -> x.replaceAll(".* timestamp=([^}]+).*", "$1"))
.collect(Collectors.toList());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.