Java Array Swap swapObjects(Object[] array, int a, int b)

Here you can find the source of swapObjects(Object[] array, int a, int b)

Description

Swaps two Objects in an array of Objects.

License

Apache License

Parameter

Parameter Description
array The array of Objects
a One of the indices of the values to be swapped
b One of the indices of the values to be swapped

Declaration

public static void swapObjects(Object[] array, int a, int b) 

Method Source Code

//package com.java2s;
/*/*from   w  w w .  jav  a  2s  . c o m*/
 * Copyright 2014 OpenRQ Team
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Swaps two Objects in an array of Objects.
     * 
     * @param array
     *            The array of Objects
     * @param a
     *            One of the indices of the values to be swapped
     * @param b
     *            One of the indices of the values to be swapped
     */
    public static void swapObjects(Object[] array, int a, int b) {

        Object tmp = array[a]; // checks for null array and illegal a index
        array[a] = array[b]; // checks for illegal b index before any changes can be made to the array
        array[b] = tmp;
    }
}

Related

  1. swapElements(final E[] arr, final int idx1, final int idx2)
  2. swapEndianFormat(byte[] b)
  3. swapInt(byte[] b, int i)
  4. swapInts(byte b[], int off, int len)
  5. swapNumbers(int i, int j, double[] array)
  6. swapOrder16(byte[] buffer, int byteOffset, int sampleCount)
  7. swapOrder32(byte[] buffer, int byteOffset, int sampleCount)
  8. swapParallel(Object[] x, Object[] y, int a, int b, int yrel)
  9. swapPerTowElement(int[] arr)