Java Array to String arrayToString2D(String title, String innerTitle, double[][] vect)

Here you can find the source of arrayToString2D(String title, String innerTitle, double[][] vect)

Description

array To String D

License

Open Source License

Declaration

public static String arrayToString2D(String title, String innerTitle,
             double[][] vect) 

Method Source Code

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

import java.text.DecimalFormat;

public class Main {
    private static DecimalFormat decimalFormat;

    public static String arrayToString2D(String title, String innerTitle,
            double[][] vect) {
        String result = title + ": \n";
        for (int i = 0; i < vect.length; i++) {
            result += printArray(innerTitle + " " + i, vect[i]) + "\n";
        }//from w  w w . j a  v a 2 s.c  om
        return result + "\n";
    }

    public static String arrayToString2D(String title, double[][] vect) {
        String result = title + ": \n";
        for (int i = 0; i < vect.length; i++) {
            result += arrayToString(vect[i]);
        }
        return result + "\n";
    }

    public static String printArray(String title, double[] vect) {
        String result = title + ": ";
        result += arrayToString(vect);
        result += "\n";
        return result;
    }

    public static String printArray(Object[] array, String separator) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < array.length; i++) {
            builder.append(array[i]);
            if (i < array.length + 1)
                builder.append(separator);
        }
        return builder.toString();
    }

    public static String arrayToString(double[] vect) {
        String result = "";
        for (int j = 0; j < vect.length; j++) {
            result += formatDouble(vect[j]);
            if (j + 1 < vect.length)
                result += " ";
        }
        return result;
    }

    public static String formatDouble(double d) {
        return decimalFormat.format(d);
    }
}

Related

  1. arrayToString(T[] array)
  2. arrayToString(T[] array)
  3. arrayToString(T[] array)
  4. arrayToString(T[] array, CharSequence start, CharSequence end)
  5. arrayToString(T[] items, String delimiter)
  6. arrayToStringArray(boolean[] values)
  7. arrayToStringDelimited(final String[] array, final String delimiter)
  8. arrayToStringNullable(String[] a)
  9. arrayToStrings(String[] s, String delimiter)