当前位置:网站首页>How to make a list sort according to the order of another list
How to make a list sort according to the order of another list
2022-06-23 18:49:00 【Monkey who loves life】
Go straight to the code :
// First of all, make sure List<User> users and List<Long> userIds
public void setListOrder(List<User> users, List<Long> userIds){
users.sort((o1,o2) -> {
int io1 = ids.indexOf(o1.getId());
int io2 = ids.indexOf(o2.getId());
if(io1 != -1){
io1 = users.size() - io1;
}
if(io2 != -1){
io2 = users.size() - io2;
}
return io2-io1;
});
}边栏推荐
- STM32 (IX) -- can
- 指标(复杂指标)定义和模型
- Set up your own website (13)
- Yapi installation
- Leetcode: hash table 07 (sum of three numbers)
- Jerry's broadcast MP3 prompt sound function [chapter]
- Stream流的使用
- Five star certification! Know that Chuangyu has passed the evaluation of the content audit service system of China Academy of Communications
- 学习编程只需要这三条建议!
- 【Qt】第十章:数据库
猜你喜欢

嵌入式开发基础之任务管理(线程管理)

杰理之串口通信 串口接收 IO 需要设置数字功能【篇】

Noah fortune passed the hearing: with an annual revenue of 4.3 billion yuan, Wang Jingbo has 49% voting rights, and Sequoia is a shareholder

微机原理第八章笔记整理

基于FPGA的电磁超声脉冲压缩检测系统 论文+源文件

QT based graphics rendering system documentation + project source code and executable exe files + system instructions

Take out Jianghu will change, and meituan "big brother" is hard to be

Leetcode question brushing: hash table 03 (happy number)

How to make good use of daily time to review efficiently?

杰理之串口设置好以后打印乱码,内部晶振没有校准【篇】
随机推荐
杰理之.强制升级【篇】
Shunted Self-Attention | 源于 PvT又高于PvT,解决小目标问题的ViT方法
[QT] Chapter 10: Database
浏览器跨域
汇编语言(1)基础知识
重磅:国产IDE发布,由阿里研发,完全开源!(高性能+高定制性)
【翻译】具有时间结构的特定信号的鲁棒提取(上)
杰理之无缝循环播放【篇】
(10)二叉树
Graffiti intelligence passed the hearing: Tencent is an important shareholder planning to return to Hong Kong for listing
【Qt】第十章:数据库
Noah fortune passed the hearing: with an annual revenue of 4.3 billion yuan, Wang Jingbo has 49% voting rights, and Sequoia is a shareholder
1、 Array -- sliding window problem -- subarray with the smallest length -- fruit basket problem
吃顿饭的时间,学会simulink之BLDC基本原理
高级计网笔记(八)
外卖江湖格局将变,美团“大哥”不好当
高级计网笔记(四)
【Qt】选择题
矩阵分析笔记(三-1)
TimerTasks笔记