Java 21 introduces the new Sequenced Collections API, which applies to all collections with a defined sequence on their elements, such as `LinkedList`, `TreeSet`, and others (see https://openjdk.org/jeps/431[JEP 431]).
For projects using Java 21 and onwards, use this API instead of workaround implementations that were necessary before Java 21.
This rule reports when a reverse copy of a list is created, but a reverse view would have been sufficient because the resulting list - as well as the original list in the scope of the resulting list - is not modified (`add`, `remove`).
`SequencedCollection.reversed()` returns a view of the original list that reflects changes in the original list, while `Collection.reverse(List)` creates a new list that is not connected with the original list.
2. It abstracts from the fact that the collection instance is a list. This results in more generic code that is easier to port, for instance, when you want to use another collection data structure.
== How to fix it
Replace `Collection.reverse(list)` with `list.reversed()`.
=== Code examples
==== Noncompliant code example
[source,java,diff-id=1,diff-type=noncompliant]
----
void foo(List<String> list) {
var reverseList = Collections.reverse(list); // Noncompliant