Here you can find the source of transpose2d(Object[][] array)
public static void transpose2d(Object[][] array)
//package com.java2s; public class Main { /**//ww w . ja va 2 s. c o m * A method for transposing square 2D arrays in-place. */ public static void transpose2d(Object[][] array) { if (array == null) { throw new IllegalArgumentException("Array must not be null"); } for (int j = 0; j < array[0].length; j++) { for (int i = j + 0; i < array.length; i++) { swap2d(array, i, j, j, i); } } } /** * A method for swapping matrix cells in-place. * @param array The target array. * @param c1 The 1st swap column. * @param r1 The 1st swap row. * @param c2 The 2nd swap column. * @param r2 The 2nd swap row. */ public static void swap2d(Object[][] array, int c1, int r1, int c2, int r2) { if (array == null) { throw new IllegalArgumentException("Array must not be null"); } Object swap = array[c1][r1]; array[c1][r1] = array[c2][r2]; array[c2][r2] = swap; } }