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 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM