Reverses the contents of the array. : Array Compare « Collections Data Structure « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » Collections Data Structure » Array Compare 




Reverses the contents of the array.
      

/*
 * Copyright WizTools.org
 * Licensed under the Apache License, Version 2.0:
 * http://www.apache.org/licenses/LICENSE-2.0
 */
//package org.wiztools.commons;

import java.util.ArrayList;
import java.util.List;

/**
 *
 @author subwiz
 */
public final class ArrayUtil {

    /**
     * Reverses the contents of the array.
     @param <T>
     @param arr The input array of objects.
     */
    public static <T> void reverse(T[] arr) {
        for(int left=0, right=arr.length-1; left < right; left++, right--) {
            final T tmp = arr[left];
            arr[left= arr[right];
            arr[right= tmp;
        }
    }

    public static void reverse(boolean[] arr) {
        for(int left=0, right=arr.length-1; left < right; left++, right--) {
            final boolean tmp = arr[left];
            arr[left= arr[right];
            arr[right= tmp;
        }
    }
    
    public static void reverse(byte[] arr) {
        for(int left=0, right=arr.length-1; left < right; left++, right--) {
            final byte tmp = arr[left];
            arr[left= arr[right];
            arr[right= tmp;
        }
    }

    public static void reverse(char[] arr) {
        for(int left=0, right=arr.length-1; left < right; left++, right--) {
            final char tmp = arr[left];
            arr[left= arr[right];
            arr[right= tmp;
        }
    }

    public static void reverse(short[] arr) {
        for(int left=0, right=arr.length-1; left < right; left++, right--) {
            final short tmp = arr[left];
            arr[left= arr[right];
            arr[right= tmp;
        }
    }

    public static void reverse(int[] arr) {
        for(int left=0, right=arr.length-1; left < right; left++, right--) {
            final int tmp = arr[left];
            arr[left= arr[right];
            arr[right= tmp;
        }
    }

    public static void reverse(long[] arr) {
        for(int left=0, right=arr.length-1; left < right; left++, right--) {
            final long tmp = arr[left];
            arr[left= arr[right];
            arr[right= tmp;
        }
    }

    public static void reverse(float[] arr) {
        for(int left=0, right=arr.length-1; left < right; left++, right--) {
            final float tmp = arr[left];
            arr[left= arr[right];
            arr[right= tmp;
        }
    }

    public static void reverse(double[] arr) {
        for(int left=0, right=arr.length-1; left < right; left++, right--) {
            final double tmp = arr[left];
            arr[left= arr[right];
            arr[right= tmp;
        }
    }
}

   
    
    
    
    
    
  














Related examples in the same category
1.Check if a text is present at the current position in a buffer for byte array
2.Check if a text is present at the current position in a buffer(char array and char array)
3.Check if a text is present at the current position in a buffer(char array and string)
4.Returns true if all the references in array1 are equal to all the references in array2 (two null references are considered equal for this test).
5.Returns true if any two items in the array are equal to one another. Any null values in the array are ignored.
6.Tests two float arrays for equality.
7.Does the source array equal the match array
8.Does this byte array begin with match array content?
9.Compares the initial elements of two arrays.
10.String search and reflection helper methodsString search and reflection helper methods
11.Checks whether two arrays are the same length, treating null arrays as length 0.
12.Checks whether two arrays are the same type taking into account multi-dimensional arrays.
13.Get the maximum value in a double array
14.Compare equality of two two-dimensional boolean array
15.Two double value arrays are almost equal
16.Find the index of the array nearest to the value.
17.Retrive the quartile value from an array
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.