集册 Java实例教程 交换数组中给定索引的两个元素。

交换数组中给定索引的两个元素。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

424
交换数组中给定索引的两个元素。


//package com.nowjava;
/**
时 代 J a v a 公 众 号 - nowjava.com
**/


public class Main {

    public static void main(String[] argv) throws Exception {

        Object[] a = new String[] { "1", "abc", "level", null,

                "nowjava.com", "asdf 123" };

        int first = 2;

        int second = 2;

        swap(a, first, second);

    }


    /** Swap two elements of an array given their indices.

     * 

     * @param a  the array to work on

     * @param first  the index of the first element to swap

     * @param second  the index of the second element to swap

     *//*来 自 时 代 J a v a 公 众 号*/

    public static void swap
展开阅读全文