LoginSignup
4
3

More than 5 years have passed since last update.

JavaのListの一部分だけをソート

Posted at

JavaのListの一部分(例えば3番目から6番目まで)だけをソートしたいときはこのようにします。
(部分ソートとは意味が異なります。)

List<Integer> list = new ArrayList<Integer>();
for(int i = 9; i != -1; --i)
  list.add(i);
Collections.sort(list.subList(3, 7));
System.out.println(list);
// [9, 8, 7, 3, 4, 5, 6, 2, 1, 0]
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3