Here you can find the source of swapObjects(Object[] array, int a, int b)
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 |
public static void swapObjects(Object[] array, int a, int b)
//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; } }