3 Ways to Reverse an Array in Java - Coding Interview Question

One of the common coding questions is, how do you reverse an array in Java? Well, there are multiple ways to solve this problem. You can reverse array by writing your own function, which loops through the array and swaps elements until the array is sorted. That's actually should you be your first approach on interviews. Later you can impress the interviewer by a couple of other tricks, which is specific to Java development world. For example, you can reverse an array by converting array to ArrayList and then use this code to reverse the ArrayList. You can also use Apache Commons ArrayUtils.reverse() method to reverse any array in Java. This method is overloaded to reverse byte, short, long, int, float, double and String array. You can use any of the method depending upon your array type.
Read more »