How do I reverse array elements order?
Category: Commons Lang, viewed: 1643 time(s).
In this example we use ArraysUtis helper class to reverse the order of array elements.
package org.kodejava.example.commons.lang; import org.apache.commons.lang.ArrayUtils; public class ArrayReverseExample { public static void main(String[] args) { // // Define colors array. // String[] colors = {"Red", "Green", "Blue", "Cyan", "Yellow", "Magenta"}; System.out.println(ArrayUtils.toString(colors)); // // Now we reverse the order of array elements using the ArrayUtils.reverse() // method. The reverse method is overloaded so we can reverse other type // of array such as boolean, char, byte, double, etc. // ArrayUtils.reverse(colors); System.out.println(ArrayUtils.toString(colors)); } } |
Related Examples
- How do I find text between two strings?
- How do I check for an empty string?
- How do I get the nearest hour, minute, second of a date?
- How do I format date and time using DateFormatUtils class?
- How do I find items in an array?
- How do I use CompareToBuilder class?
- How do I use ReflectionToStringBuilder class?
- How do I convert array of object to array of primitive?
- How do I convert an array to a Map?
- How do I count word occurrences in a string?
|
|