1 List<String> stringList = Arrays.asList("A", "B", "C");
2 Collections.reverse(stringList);
3 assertThat(stringList).containsExactly("C", "B", "A");
1int length = array.length;
2 for(int i=0;i<length/2;i++) {
3 int swap = array[i];
4 array[i] = array[length-i-1];
5 array[length-i-1] = swap;
6 }
7or
8Collections.reverse(Arrays.asList(array));
1int length = array.length;
2 for(int i=0;i<length/2;i++) {
3 int swap = array[i];
4 array[i] = array[length-i-1];
5 array[length-i-1] = swap;
6 }
1public class ReverseArray {
2 public static void main(String[] args) {
3 //Initialize array
4 int [] arr = new int [] {1, 2, 3, 4, 5};
5 System.out.println("Original array: ");
6 for (int i = 0; i < arr.length; i++) {
7 System.out.print(arr[i] + " ");
8 }
9 System.out.println();
10 System.out.println("Array in reverse order: ");
11 //Loop through the array in reverse order
12 for (int i = arr.length-1; i >= 0; i--) {
13 System.out.print(arr[i] + " ");
14 }
15 }
16}
1//java program to reverse array using for loop
2public class ReverseArrayDemo
3{
4 public static void main(String[] args)
5 {
6 int[] arrNumbers = new int[]{2, 4, 6, 8, 10};
7 System.out.println("Given array: ");
8 for(int a = 0; a < arrNumbers.length; a++)
9 {
10 System.out.print(arrNumbers[a] + " ");
11 }
12 System.out.println("Reverse array: ");
13 // looping array in reverse order
14 for(int a = arrNumbers.length - 1; a >= 0; a--)
15 {
16 System.out.print(arrNumbers[a] + " ");
17 }
18 }
19}
1// reverse array
2
3for(int i=intArray.length-1;i>=0;i--)
4 System.out.print(intArray[i] + " ");