package yw.fanxing;

/**
 * 自定义泛型测试
 * 
 * 写一个方法,将任意数组的任意两个位置的数据进行交换
 * 
 * @author yw-tony
 * 
 */
public class CustomGTest {
    /**
     * 程序的入口main方法
     * @param args
     */
    public static void main(String[] args) {
        String[] strs = { "yw", "sun", "xiao" };
        swarp(strs, 1, 2);
    }
    /**
     * 将传入的任意数组的任意的两个位置进行交换
     * @param t
     * @param i
     * @param j
     */
    public static <T> void swarp(T[] t, int i, int j) {
        //交换前的数据位置打印
        for (int k = 0; k < t.length; k++) {
            System.out.println(t[k]);
        }
        T temp = t[i];
        t[i] = t[j];
        t[j] = temp;
        System.out.println("**************************");
        //交换后的数据位置打印
        for (int k = 0; k < t.length; k++) {
            System.out.println(t[k]);
        }
    }
}

 

相关文章:

  • 2022-12-23
  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
  • 2022-12-23
相关资源
相似解决方案