java中已经排序的列表中插入新值

 1 static List<Integer> insertSortedList(){
 2         List<Integer> nums = new ArrayList<Integer>();
 3         nums.add(10);
 4         nums.add(9);
 5         nums.add(7);
 6         nums.add(4);
 7         nums.add(6);
 8         nums.add(5);
 9         Collections.sort(nums);
10         int num=0;
11         int length=nums.size();
12         int loc=0;
13         for(int i=0;i<length;i++){
14             if(num>nums.get(i)){
15                 loc++;
16             }
17         }
18         nums.add(loc, num);
19         return nums;
20     }

 

posted @ 2016-04-05 20:42  ppjj  阅读(492)  评论(0编辑  收藏  举报