As we have seen the implementations of a List are :
Let us see the ArrayList implementation
Reversal of a List can be done using Collections.reverse() method. It is independent of the alphabets. And is not a sort. It is just a reversal.
import java.util.ArrayList; import java.util.Collections; import java.util.List; public class MyApplication { public static void main(String[] args) { Listx = new ArrayList<>(); x.add("Mohan"); x.add("Kriti"); x.add("Salim"); Collections.reverse(x); for (String data : x) { System.out.println(data); } } }
So, in the above code we have created a List,
Listx = new ArrayList<>();
And initialised three names to the variable x,
x.add("Mohan"); x.add("Kriti"); x.add("Salim");
Below is how the values are positioned in the List,
Then we have used the Collections.reverse(x) Method to reverse the elements of the List x.
Collections.reverse(x);
And the List x gets sorted in reverse order with Salim as the first value, Mohan second and Kriti as the third.
And we get the below output.