简体   繁体   中英

Best way to sort part of a list (Java)

I need to sort the end of a list [6, 2, 3, 5, 4, 1, 0] --> [6, 2, 3, 0, 1, 4, 5] which can be easily done with arrays Arrays.sort(sequence, i, sequence.size()); but how would I do it with lists when Collections.sort doesn't allow start and end parameters?

You can pass sublist in Collection.sort()..

List<Integer> a= Arrays.asList(6, 2, 3, 5, 4, 1, 0);
Collections.sort(a.subList(3,a.size()));
a.stream().forEach(System.out::println);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM