Java Matrix to String toString(int[][] matrix)

Here you can find the source of toString(int[][] matrix)

Description

Format matrix as String, by joining Arrays.toString of each row

License

Open Source License

Parameter

Parameter Description
matrix the matrix to format

Return

the matrix String

Declaration

public static String toString(int[][] matrix) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;

public class Main {
    /**/*from ww w  .  ja v  a 2 s . co m*/
     * Format matrix as String, by joining Arrays.toString of each row
     * @param matrix the matrix to format
     * @return the matrix String
     */
    public static String toString(int[][] matrix) {
        StringBuilder builder = new StringBuilder();
        builder.append("[");
        if (matrix.length > 0) {
            builder.append(Arrays.toString(matrix[0]));
            for (int i = 1; i < matrix.length; ++i) {
                builder.append(", ").append(Arrays.toString(matrix[i]));
            }
        }
        builder.append("]");
        return builder.toString();
    }
}

Related

  1. toString(double[][] A)
  2. toString(double[][] array)
  3. toString(double[][] data)
  4. toString(int partition[][])
  5. toString(int[][] a)
  6. toString(Object[][] arr)