public static void main(String[] args) {
List<Integer> list=new ArrayList<>();
Random random=new Random();
for(int i=0;i<20;i++){
list.add(random.nextInt(100));
}
list.sort(null);//自然排序
System.out.println(list);
list.subList(5,15).sort((i1,i2)->i2-i1);//指定位置降序,第六个到第16个进行降序
System.out.println(list);
}
结果
[0, 13, 15, 17, 19, 22, 37, 45, 45, 46, 48, 53, 54, 63, 68, 70, 76, 82, 83, 87]
[0, 13, 15, 17, 19, 68, 63, 54, 53, 48, 46, 45, 45, 37, 22, 70, 76, 82, 83, 87]