list java reverse order code example
Example 1: how to reverse a list in java
List<String> stringList = Arrays.asList("A", "B", "C");
Collections.reverse(stringList);
assertThat(stringList).containsExactly("C", "B", "A");
Example 2: how to reverse order of arraylist
ArrayList<Integer> arrlist = new ArrayList<Integer>();
//This is how to reverse arrlist's oringinal order.
Collections.reverse(arrlist);
//This is how to sort in a reverse order
Collections.sort(arrlist, Collections.reverseOrder());