Java examples for Collection Framework:Array Reverse
Reverse an array.
/**/* w w w .j a v a2 s. co m*/ * Copyright (C) 2011 NetMind Consulting Bt. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ //package com.java2s; public class Main { public static void main(String[] argv) throws Exception { byte[] b = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 }; System.out.println(java.util.Arrays.toString(reverse(b))); } /** * Reverse an array. */ public static byte[] reverse(byte[] b) { byte[] b2 = new byte[b.length]; for (int i = 0; i < b.length; i++) b2[b.length - 1 - i] = b[i]; return b2; } }