How do I reverse array elements order?

In this example we are going to use the ArraysUtils helper class from the Apache Commons Lang library to reverse the order of array elements. The method to reverse the order of array elements is ArrayUtils.reverse() method.

The ArrayUtils.reverse() method is overloaded, so we can reverse another type of array such as java.lang.Object, long, int, short, char, byte, double, float and boolean.

package org.kodejava.commons.lang;

import org.apache.commons.lang3.ArrayUtils;

public class ArrayReverseExample {

    public static void main(String[] args) {
        // Define the "colors" array.
        String[] colors = {"Red", "Green", "Blue", "Cyan", "Yellow", "Magenta"};

        // Now we reverse the order of array elements.

Here is the output of the code snippet above:


Maven Dependencies


Maven Central


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.