Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在java中将列表解包到子列表_Java_Arraylist - Fatal编程技术网

如何在java中将列表解包到子列表

如何在java中将列表解包到子列表,java,arraylist,Java,Arraylist,我通过以下代码获得了一个列表: 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{{pac

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

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

我们可以利用此处的流生成两个列表:

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());
List packetsList=single.stream()
.map(x->x.replaceAll(“.*packetsLost=(\\d+).*”,“$1”))
.collect(Collectors.toList());
List timestampsList=single.stream()
.map(x->x.replaceAll(“.*timestamp=([^}]+)*”,“$1”))
.collect(Collectors.toList());

此外,您的预期输出与输入不一致。这。。。似乎假定输入是字符串列表。我改变了我的问题,你可以帮我,但我帮不了你,因为你的新预期输出不能用字符串表示。你的问题忽略了我们需要再次帮助你的信息。
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());