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 }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
  • 2022-12-23
  • 2022-12-23
  • 2022-03-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-03
  • 2021-10-21
相关资源
相似解决方案