越努力,越幸运

朱季谦

腾讯云社区2022年度最佳作者、阿里云专家博主认证

java将list中某个元素放在首位

java将list中某个元素放在首位

复制代码
 1 List<Example> example = exampleRepository.list();
 2 
 3 //将list里的某个字符串默认排列在list第一个位置
 4 if(null != example&& example.size() > 0){
 5     for(int index = 0 , length = example.size() ; index < length ; index++){
 6         if("testData".equals(example.get(index).getLabel())){
 7             example temp = example.get(0);
 8             example.set(0, example.get(index));
 9             example.set(index, temp);
10         }
11     }
12 }
复制代码

 

posted @   朱季谦  阅读(11683)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· Ollama——大语言模型本地部署的极速利器
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· Windows编程----内核对象竟然如此简单?
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
点击右上角即可分享
微信分享提示