Java Matrix to String toString(double[][] data)

Here you can find the source of toString(double[][] data)

Description

Convert a 2D array to string

License

Open Source License

Parameter

Parameter Description
data a parameter

Declaration

public static String toString(double[][] data) 

Method Source Code


//package com.java2s;
/*/*from w ww.j a v  a2  s . com*/
Copyright (c) 2014 cs.nmsu.edu
    
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
    
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
    
The Software shall be used for Good, not Evil.
    
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

import java.util.*;

public class Main {
    /**
     * Convert a 2D array to string
     * @param data
     * @return
     */
    public static String toString(double[][] data) {
        StringBuffer buf = new StringBuffer();

        //added by Huiping
        buf.append("row num = word num=" + data.length + "\n");
        if (data.length > 0)
            buf.append("col num = doc num = " + data[0].length + "\n");
        //end of adding

        for (int c0 = 0; c0 < data.length; c0++) {
            double[] row = data[c0];
            buf.append(Arrays.toString(row)).append("\n");
        }
        return buf.toString();
        //return Arrays.deepToString(data);
    }
}

Related

  1. matrixToString(int[][] m)
  2. matrixToString(int[][] matrix, String sep)
  3. matrixToString(String[][] m)
  4. toString(double[][] A)
  5. toString(double[][] array)
  6. toString(int partition[][])
  7. toString(int[][] a)
  8. toString(int[][] matrix)
  9. toString(Object[][] arr)