private List<ConvertibleFundVO> getResortedConvertibleList(List<ConvertibleFundVO> convertibleFundList, String accountNo) { if (CollectionUtils.isEmpty(convertibleFundList)) { return convertibleFundList; } List<String> prodCodes = operateService .queryCollectProdCodes(new QueryCollectProdCodesReqBO().setAccountNo(accountNo)) .getProdCodes(); if (CollectionUtils.isEmpty(prodCodes)) { return convertibleFundList; } return convertibleFundList .stream() .sorted((x, y) -> { int indexX = prodCodes.indexOf(x.getTargetFundCode()); int indexY = prodCodes.indexOf(y.getTargetFundCode()); if (indexX == -1) { return 1; } if (indexY == -1) { return -1; } return indexX - indexY; } ).map(r -> r.setCollectFlag(prodCodes.contains(r.getTargetFundCode()))) .collect(Collectors.toList()); }// 示例public static void main(String[] args) { String[] regulation = {"诸葛亮", "鲁班", "xzcx", "貂蝉", "吕布"}; final List regulationOrder = Arrays.asList(regulation); String[] ordered = {"nice", "貂蝉", "诸葛亮", "xzcx", "吕布", "貂蝉", "鲁班", "诸葛亮", "貂蝉", "鲁班", "诸葛亮", "hahahahah", "adsad"}; List orderedList = Arrays.asList(ordered); Collections.sort(orderedList, (o1, o2) -> { int io1 = regulationOrder.indexOf(o1); int io2 = regulationOrder.indexOf(o2); if (io1 == -1) { return 1; } if (io2 == -1) { return -1; } return io1 - io2; }); System.out.println(orderedList);}