Here you can find the source of transposeSquareMatrix(T[][] matrixT)
@SuppressWarnings("unchecked") public static <T> T[][] transposeSquareMatrix(T[][] matrixT)
//package com.java2s; //License from project: Open Source License public class Main { @SuppressWarnings("unchecked") public static <T> T[][] transposeSquareMatrix(T[][] matrixT) { Object[][] matrix = new Object[matrixT.length][matrixT.length]; int matrixSize = matrixT.length; for (int i = 0; i < matrixSize; i++) { for (int j = 0; j < matrixSize; j++) { matrix[i][j] = (Object) matrixT[j][i]; }//from w ww . ja v a 2 s. c o m } return (T[][]) matrix; } public static int[][] transposeSquareMatrix(int[][] matrixT) { int[][] matrix = new int[matrixT.length][matrixT.length]; int matrixSize = matrixT.length; for (int i = 0; i < matrixSize; i++) { for (int j = 0; j < matrixSize; j++) { matrix[i][j] = matrixT[j][i]; } } return matrix; } }