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 }
原文地址:https://www.cnblogs.com/zhujiqian/p/12546658.html