Java Utililty Methods Matrix to String

List of utility methods to do Matrix to String

Description

The list of methods to do Matrix to String are organized into topic(s).

Method

StringArray2DToString(double[][] array)
print 2D array to string (matrix)
final StringBuffer str = new StringBuffer();
int i = 0, j = 0;
for (i = 0; i < array.length; i++) {
    for (j = 0; j < array[i].length; j++) {
        str.append(" " + array[i][j]);
    str.append("\n");
str.append("\n");
return str.toString();
Stringarray2DToString(int[][] grid)
array D To String
if (grid == null) {
    return null;
StringBuilder sb = new StringBuilder();
sb.append("[");
for (int i = 0; i < grid.length; i++) {
    sb.append(Arrays.toString(grid[i]));
sb.append("]");
return sb.toString();
StringformatTable(String[][] table)
Formats the given array of arrays of String s
if (table == null) {
    throw new NullPointerException("table == null");
final List<List<String>> list = new ArrayList<List<String>>();
for (final String[] a : table) {
    final List<String> list2 = new ArrayList<String>();
    for (final String s : a) {
        list2.add(s);
...
Stringmatrix2string(int[][] matrix)
matrixstring
if (matrix == null || matrix.length == 0 || matrix[0].length == 0)
    return null;
String str = String.valueOf(matrix[0][0]);
for (int i = 0; i < matrix.length; i++) {
    for (int j = 0; j < matrix[0].length; j++) {
        if (i == 0 && j == 0)
            continue;
        str += " " + matrix[i][j];
...
Stringmatrix_toString(int[][] matrix)
matrito String
StringBuilder sb = new StringBuilder();
for (int i = 0; i < matrix.length; i++) {
    sb.append("[ ");
    for (int j = 0; j < matrix[0].length; j++) {
        sb.append(matrix[i][j] + " ");
    sb.append("]\n");
return sb.toString();
StringmatrixToString(double[][] matrix, int digit, String[] names)
matrix To String
StringBuilder output = new StringBuilder();
for (int i = 0; i < matrix.length; i++) {
    if (names != null)
        output.append(names[i]).append("\t");
    output.append(arrayToString(matrix[i], digit)).append("\n");
return output.toString();
StringmatrixToString(float[][][] matrix)
Write the full matrix to a string
StringBuffer out = new StringBuffer();
for (int k = 0; k < matrix[0][0].length; k++) {
    for (int i = matrix.length - 1; i >= 0; i--) {
        for (int j = 0; j < matrix[0].length; j++) {
            out.append(matrix[i][j][k]);
            out.append(SEPARATOR);
        out.append("\n");
...
StringmatrixToString(int[][] m)
Creates and returns a formatted string represenation of the input matrix m
String str = "";
for (int i = 0; i < m.length; i++) {
    str += ((str.length() > 0) ? ",\n" : "") + "[";
    for (int j = 0; j < m[0].length; j++)
        str += m[i][j] + ((j < m[0].length - 1) ? ", " : "");
    str += "]";
return str;
...
StringmatrixToString(int[][] matrix, String sep)
matrix To String
StringBuilder sb = new StringBuilder();
for (int i = 0; i < matrix.length; i++) {
    for (int j = 0; j < matrix[i].length; j++) {
        sb.append(matrix[i][j]).append(sep);
    sb.append("\n");
return sb.toString();
...
StringmatrixToString(String[][] m)
matrix To String
StringBuilder expectedStr = new StringBuilder();
expectedStr.append("{");
for (String[] strings : m) {
    expectedStr.append("{");
    for (String s : strings) {
        expectedStr.append('"');
        expectedStr.append(s);
        expectedStr.append('"');
...