reverse Array - Java Collection Framework

Java examples for Collection Framework:Array Reverse

Description

reverse Array

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String[] array = new String[] { "1", "abc", "level", null,
                "java2s.com", "asdf 123" };
        System.out.println(java.util.Arrays.toString(reverseArray(array)));
    }/* ww w. ja  v a2  s. c om*/

    public static String[] reverseArray(String[] array) {
        String[] arrayReversed = new String[array.length];
        for (int i = 0; i < array.length; i++) {
            arrayReversed[array.length - 1 - i] = array[i];
        }

        return arrayReversed;
    }
}

Related Tutorials