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());
public static void main(String[] args) {
ArrayList<Integer>list = new ArrayList<>();
for(int i = 1; i < 6; i++){ // bu element index degil.
list.add(i);
}
System.out.println(list); // [1, 2, 3, 4, 5]
for (int i = list.size()-1; i >= 0; i--) {
int each = list.get(i); // unboxing
System.out.print(each + " "); // 5 4 3 2 1
}
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());
public static void main(String[] args) {
ArrayList<Integer>list = new ArrayList<>();
for(int i = 1; i < 6; i++){ // bu element index degil.
list.add(i);
}
System.out.println(list); // [1, 2, 3, 4, 5]
for (int i = list.size()-1; i >= 0; i--) {
int each = list.get(i); // unboxing
System.out.print(each + " "); // 5 4 3 2 1
}