李东勇-demo

反转数组:以Sting数组为例子:
package com;


public class Resversion
{
    public static void main(String[] args)
    {
        //反转之前
        String[] pre = new String[]{"a","b","c","d"};
        Resversion res = new Resversion();
        pre = res.resversionArray(pre);
    }
    /**
     * 反转数组
     * @param pre
     * @return
     */
    public String[] resversionArray(String[] pre)
    {
        String[] result = new String[pre.length];
        int index = 0;
        for (int i = pre.length; i>0; i--)
        {
            result[index] = pre[i-1];
            index++;
        }
        return result;
    }
}

你可能感兴趣的:(demo)