Opening Hours :7AM to 9PM
class ArrayReverse { public void printReverse(int[] arr) { for (int i = arr.length - 1; i >= 0; i--) { System.out.print(arr[i] + " "); } } } public class Main { public static void main(String[] args) { ArrayReverse ar=new ArrayReverse(); int[] arr = {1, 2, 3, 4, 5}; ar.printReverse(arr); } }This program uses a for-loop to iterate through the array in reverse order and print each element. It starts the loop counter at arr.length - 1, which is the index of the last element in the array, and goes backwards until the counter is greater than or equal to zero.
import java.util.ArrayList; import java.util.Collections; public class Main { public static void main(String[] args) { int[] arr = {1, 2, 3, 4, 5}; ArrayList<Integer> arrList = new ArrayList<Integer>(); for(int i=0;i<arr.length;i++){ arrList.add(arr[i]); } Collections.reverse(arrList); for (int i : arrList) { System.out.print(i + " "); } } }In both examples, the output will be: