var numbers = new ArrayList<Integer>(100);
for (var i = 1; i <= 100; i++) {
numbers.add(i);
}
This is a series of numbers (just for example)
But, it starts with the wrong number.
I need it to start with 21, not 1.
Modifying the cycle would be unnecessarily complex. It is easier to divide the ArrayList
into two List
and swap them.
numbers = Stream.concat(numbers.subList(20, 100).stream(), numbers.subList(0, 20).stream()).collect(Collectors.toCollection(ArrayList::new));
I used the concat
method, which merges two ArrayLists
and subList
method, which returns a part of the ArrayList
.
However, it is illogical to create a new ArrayList
that is only differently ordered.
It would be enough to use the sorted method, but I don't know how to write it to sort it correctly.
Please help
Thank you