在java中,有个List<PassengerDetailInfoPhoneNbr> phoneList的集合,数据为[{ "passengerPhoneNbr": "13614383602", "ecifPhoneNbr": "", "agentPhoneNbr": "13614380243", "customPhoneNbr": "", "chnName": "张忠", "oldFltDt": "2023-05-31 08:00:00", "oldDptAirportCd": "DSN", "oldArvAirportCd": "CGQ", "oldFltNbr": "KN2359", "newFltDt": "2023-06-01 08:00:00", "newDptAirportCd": "DSN", "newArvAirportCd": "CGQ", "newFltNbr": "KN2359" }],现在根据passengerPhoneNbr,ecifPhoneNbr,agentPhoneNbr,customPhoneNbr,去重新生成数据,最后的格式为[{ "phoneEncryption": "13614383602", "chnName": "张忠", "oldFltDt": "2023-05-31 08:00:00", "oldDptAirportCd": "DSN", "oldArvAirportCd": "CGQ", "oldFltNbr": "KN2359", "newFltDt": "2023-06-01 08:00:00", "newDptAirportCd": "DSN", "newArvAirportCd": "CGQ", "newFltNbr": "KN2359" }, { "phoneEncryption": "", "chnName": "张忠", "oldFltDt": "2023-05-31 08:00:00", "oldDptAirportCd": "DSN", "oldArvAirportCd": "CGQ", "oldFltNbr": "KN2359", "newFltDt": "2023-06-01 08:00:00", "newDptAirportCd": "DSN", "newArvAirportCd": "CGQ", "newFltNbr": "KN2359" }, { "phoneEncryption": "13614380243", "chnName": "张忠", "oldFltDt": "2023-05-31 08:00:00", "oldDptAirportCd": "DSN", "oldArvAirportCd": "CGQ", "oldFltNbr": "KN2359", "newFltDt": "2023-06-01 08:00:00", "newDptAirportCd": "DSN", "newArvAirportCd": "CGQ", "newFltNbr": "KN2359" }, { "phoneEncryption": "", "chnName": "张忠", "oldFltDt": "2023-05-31 08:00:00", "oldDptAirportCd": "DSN", "oldArvAirportCd": "CGQ", "oldFltNbr": "KN2359", "newFltDt": "2023-06-01 08:00:00", "newDptAirportCd": "DSN", "newArvAirportCd": "CGQ", "newFltNbr": "KN2359" } ]
时间: 2023-07-09 19:56:11 浏览: 64
Java8 将List<Integer> 转换成以逗号分割的String字符串
你可以使用Java 8的Stream API和lambda表达式来实现该操作。首先,你需要创建一个新的PassengerDetailInfoPhoneNbr对象的列表。然后,使用forEach()方法对原始列表中的每个元素进行遍历,根据每个元素的passengerPhoneNbr、ecifPhoneNbr、agentPhoneNbr、customPhoneNbr属性的值来创建新的PassengerDetailInfoPhoneNbr对象,并将其添加到新的列表中。最后,将新列表作为结果返回即可。以下是代码示例:
```
List<PassengerDetailInfoPhoneNbr> phoneList = ... // 从某个地方获取PassengerDetailInfoPhoneNbr对象列表
List<PassengerDetailInfoPhoneNbr> newPhoneList = new ArrayList<>();
phoneList.forEach(phone -> {
// 根据passengerPhoneNbr、ecifPhoneNbr、agentPhoneNbr、customPhoneNbr属性的值创建新的PassengerDetailInfoPhoneNbr对象
PassengerDetailInfoPhoneNbr newPhone1 = new PassengerDetailInfoPhoneNbr();
newPhone1.setPhoneEncryption(phone.getPassengerPhoneNbr());
newPhone1.setChnName(phone.getChnName());
newPhone1.setOldFltDt(phone.getOldFltDt());
newPhone1.setOldDptAirportCd(phone.getOldDptAirportCd());
newPhone1.setOldArvAirportCd(phone.getOldArvAirportCd());
newPhone1.setOldFltNbr(phone.getOldFltNbr());
newPhone1.setNewFltDt(phone.getNewFltDt());
newPhone1.setNewDptAirportCd(phone.getNewDptAirportCd());
newPhone1.setNewArvAirportCd(phone.getNewArvAirportCd());
newPhone1.setNewFltNbr(phone.getNewFltNbr());
newPhoneList.add(newPhone1);
PassengerDetailInfoPhoneNbr newPhone2 = new PassengerDetailInfoPhoneNbr();
newPhone2.setPhoneEncryption(phone.getEcifPhoneNbr());
newPhone2.setChnName(phone.getChnName());
newPhone2.setOldFltDt(phone.getOldFltDt());
newPhone2.setOldDptAirportCd(phone.getOldDptAirportCd());
newPhone2.setOldArvAirportCd(phone.getOldArvAirportCd());
newPhone2.setOldFltNbr(phone.getOldFltNbr());
newPhone2.setNewFltDt(phone.getNewFltDt());
newPhone2.setNewDptAirportCd(phone.getNewDptAirportCd());
newPhone2.setNewArvAirportCd(phone.getNewArvAirportCd());
newPhone2.setNewFltNbr(phone.getNewFltNbr());
newPhoneList.add(newPhone2);
PassengerDetailInfoPhoneNbr newPhone3 = new PassengerDetailInfoPhoneNbr();
newPhone3.setPhoneEncryption(phone.getAgentPhoneNbr());
newPhone3.setChnName(phone.getChnName());
newPhone3.setOldFltDt(phone.getOldFltDt());
newPhone3.setOldDptAirportCd(phone.getOldDptAirportCd());
newPhone3.setOldArvAirportCd(phone.getOldArvAirportCd());
newPhone3.setOldFltNbr(phone.getOldFltNbr());
newPhone3.setNewFltDt(phone.getNewFltDt());
newPhone3.setNewDptAirportCd(phone.getNewDptAirportCd());
newPhone3.setNewArvAirportCd(phone.getNewArvAirportCd());
newPhone3.setNewFltNbr(phone.getNewFltNbr());
newPhoneList.add(newPhone3);
PassengerDetailInfoPhoneNbr newPhone4 = new PassengerDetailInfoPhoneNbr();
newPhone4.setPhoneEncryption(phone.getCustomPhoneNbr());
newPhone4.setChnName(phone.getChnName());
newPhone4.setOldFltDt(phone.getOldFltDt());
newPhone4.setOldDptAirportCd(phone.getOldDptAirportCd());
newPhone4.setOldArvAirportCd(phone.getOldArvAirportCd());
newPhone4.setOldFltNbr(phone.getOldFltNbr());
newPhone4.setNewFltDt(phone.getNewFltDt());
newPhone4.setNewDptAirportCd(phone.getNewDptAirportCd());
newPhone4.setNewArvAirportCd(phone.getNewArvAirportCd());
newPhone4.setNewFltNbr(phone.getNewFltNbr());
newPhoneList.add(newPhone4);
});
// 返回新的PassengerDetailInfoPhoneNbr对象列表
return newPhoneList;
```
阅读全文