Write a Java program to reverse an array

Below program illustrates how to reverse an array using Java:

public class ReverseArray {
 
	public static void main(String[] args) {
		int[] a = { 1, 2, 3, 4, 5, 6 };
		System.out.println(Arrays.toString(reverse(a)));
	}
 
	private static int[] reverse(int[] a) {
		int len = a.length;
		for (int i = 0, j = len - 1; i < len / 2; i++, j--) {
			int temp = a[i];
			a[i] = a[j];
			a[j] = temp;
		}
		return a;
	}
 
}

Author: Mahesh

Technical Lead with 10 plus years of experience in developing web applications using Java/J2EE and web technologies. Strong in design and integration problem solving skills. Ability to learn, unlearn and relearn with strong written and verbal communications.