亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將java中的列表解壓縮為子列表

如何將java中的列表解壓縮為子列表

12345678_0001 2023-03-31 15:00:52
我通過以下代碼得到了一個列表: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());


查看完整回答
反對 回復 2023-03-31
  • 1 回答
  • 0 關注
  • 142 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號