我通过以下代码得到了一个列表: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]
1 回答
婷婷同学_
TA贡献1844条经验 获得超8个赞
我们可以在这里使用流来生成两个列表:
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());
添加回答
举报
0/150
提交
取消