java 两个list排序_Java 两个List按照其中一个List元素顺序对另一个List元素进行排序...

` 根据orderList顺序排序,orderList不存在的元素放置在targetList最后面

// 根据orderList顺序排序,orderList不存在的元素放置在targetList最后面

private static void sort1(List targetList, List orderList) {

targetList.sort(((o1, o2) -> {

int io1 = orderList.indexOf(o1);

int io2 = orderList.indexOf(o2);

if (io1 != -1) {

io1 = targetList.size() - io1;

}

if (io2 != -1) {

io2 = targetList.size() - io2;

}

return io2 - io1;

}));

}

//如果targetList为list,则需要 get出 key 相同字段进行比较

private static void sort1(List targetList, List orderList) {

targetList.sort(((o1, o2) -> {

int io1 = orderList.indexOf(o1.get出targetList与orderList相同的key);

int io2 = orderList.indexOf(o2.get出targetList与orderList相同的key;

if (io1 != -1) {

io1 = targetList.size() - io1;

}

if (io2 != -1) {

io2 = targetList.size() - io2;

}

return io2 - io1;

}));

}

` 根据orderList顺序排序,orderList不存在的元素放置在targetList最前面

// 根据orderList顺序排序,orderList不存在的元素放置在targetList最前面

private static void sort2(List targetList, List orderList) {

targetList.sort(((o1, o2) -> {

int io1 = orderList.indexOf(o1);

int io2 = orderList.indexOf(o2);

return io1 - io2;

}));

}

//如果targetList为list,则需要 get出 key 相同字段进行比较

private static void sort2( List targetList, List orderList) {

targetList.sort(((o1, o2) -> {

int io1 = orderList.indexOf(o1.get出targetList与orderList相同的key);

int io2 = orderList.indexOf(o2.get出targetList与orderList相同的key);

return io1 - io2;

}));

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值