测试代码如下:—-可以直接运行的

    1. private static void xunhaun() {
    2. List<Td51CustRisk> td51CustRiskList = new ArrayList<>();
    3. Td51CustRisk td51CustRisk1 = new Td51CustRisk();
    4. td51CustRisk1.setCustNo("123");
    5. Td51CustRisk td51CustRisk2 = new Td51CustRisk();
    6. td51CustRisk2.setCustNo("234");
    7. Td51CustRisk td51CustRisk3 = new Td51CustRisk();
    8. td51CustRisk3.setCustNo("345");
    9. Td51CustRisk td51CustRisk4 = new Td51CustRisk();
    10. td51CustRisk4.setCustNo("456");
    11. td51CustRiskList.add(td51CustRisk1);
    12. td51CustRiskList.add(td51CustRisk2);
    13. td51CustRiskList.add(td51CustRisk3);
    14. td51CustRiskList.add(td51CustRisk4);
    15. List<Map<String, Object>> custInfoList = new ArrayList<>();
    16. Map<String, Object> map1 = new HashMap<>();
    17. map1.put("custNo", "345");
    18. map1.put("custName", "345的名字");
    19. map1.put("appOrg", "345的appOrg");
    20. map1.put("custType", "345的custType");
    21. Map<String, Object> map2 = new HashMap<>();
    22. map2.put("custNo", "234");
    23. map2.put("custName", "234的名字");
    24. map2.put("appOrg", "234的appOrg");
    25. map2.put("custType", "234的custType");
    26. Map<String, Object> map3 = new HashMap<>();
    27. map3.put("custNo", "123");
    28. map3.put("custName", "123的名字");
    29. map3.put("appOrg", "123的appOrg");
    30. map3.put("custType", "123的custType");
    31. Map<String, Object> map4 = new HashMap<>();
    32. map4.put("custNo", "456");
    33. map4.put("custName", "456的名字");
    34. map4.put("appOrg", "456的appOrg");
    35. map4.put("custType", "456的custType");
    36. custInfoList.add(map1);
    37. custInfoList.add(map2);
    38. custInfoList.add(map3);
    39. custInfoList.add(map4);
    40. Map<String, Td51CustRisk> custRiskListMap = td51CustRiskList.stream().collect(
    41. Collectors.toMap(w -> w.getCustNo(),
    42. w -> w));
    43. for (int i = 0; i < custInfoList.size(); i++) {
    44. //匹配客户号
    45. String custNo = custInfoList.get(i).get("custNo").toString();
    46. Td51CustRisk td51CustRisk = custRiskListMap.get(custNo);
    47. //客户所属机构
    48. Object appOrg = custInfoList.get(i).get("appOrg");
    49. td51CustRisk.setOrgKey(String.valueOf(appOrg));
    50. //客户名称
    51. Object custName = custInfoList.get(i).get("custName");
    52. if (!ObjectUtils.isEmpty(custName)) {
    53. td51CustRisk.setCustCnName(String.valueOf(custName));
    54. }
    55. //客户类型
    56. Object custType = custInfoList.get(i).get("custType");
    57. if (!ObjectUtils.isEmpty(custType)) {
    58. td51CustRisk.setCustType(String.valueOf(custType));
    59. }
    60. System.out.println("custNo:" + td51CustRisk.getCustNo() + "--appOrg:" + td51CustRisk.getOrgKey() + "--custName:" + td51CustRisk.getCustCnName() + "---custType:" + td51CustRisk.getCustType());
    61. }
    62. }

    实体类:

    1. package dto;
    2. public class Td51CustRisk {
    3. private String custNo;
    4. private String custCnName;
    5. private String orgKey;
    6. private String custType;
    7. public String getCustNo() {
    8. return custNo;
    9. }
    10. public void setCustNo(String custNo) {
    11. this.custNo = custNo;
    12. }
    13. public String getCustCnName() {
    14. return custCnName;
    15. }
    16. public void setCustCnName(String custCnName) {
    17. this.custCnName = custCnName;
    18. }
    19. public String getOrgKey() {
    20. return orgKey;
    21. }
    22. public void setOrgKey(String orgKey) {
    23. this.orgKey = orgKey;
    24. }
    25. public String getCustType() {
    26. return custType;
    27. }
    28. public void setCustType(String custType) {
    29. this.custType = custType;
    30. }
    31. }

    运行的结果:
    image.png

    解释:
    将list通过java8特性 改成map的形式—-将custNo作为map的key值,保证唯一性。

    Map custRiskListMap = td51CustRiskList.stream().collect(
    Collectors.toMap(w -> w.getCustNo(),
    w -> w));
    再通过for循环—-根据custNo做匹配即可