猿问

如何将java中的列表解压缩为子列表

我通过以下代码得到了一个列表:


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}}]

我是 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]


12345678_0001
浏览 83回答 1
1回答

婷婷同学_

我们可以在这里使用流来生成两个列表:List<String>&nbsp;packetsList&nbsp;=&nbsp;single.stream() &nbsp;&nbsp;&nbsp;&nbsp;.map(x&nbsp;->&nbsp;x.replaceAll(".*packetsLost=(\\d+).*",&nbsp;"$1")) &nbsp;&nbsp;&nbsp;&nbsp;.collect(Collectors.toList()); List<String>&nbsp;timestampsList&nbsp;=&nbsp;single.stream() &nbsp;&nbsp;&nbsp;&nbsp;.map(x&nbsp;->&nbsp;x.replaceAll(".*&nbsp;timestamp=([^}]+).*",&nbsp;"$1")) &nbsp;&nbsp;&nbsp;&nbsp;.collect(Collectors.toList());
随时随地看视频慕课网APP

相关分类

Java
我要回答