Java Array to String arrayToString(float[] a)

Here you can find the source of arrayToString(float[] a)

Description

array To String

License

Open Source License

Declaration

public static String arrayToString(float[] a) 

Method Source Code

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

public class Main {
    public static String arrayToString(float[] a) {
        String result = "";
        for (int i = 0; i < a.length; i++) {
            result += floatToString(a[i]) + " ";
        }//from w ww . j  a v a 2s.  c  o m
        return result;
    }

    public static String arrayToString(double[] a) {
        String result = "";
        for (int i = 0; i < a.length; i++) {
            result += a[i] + " ";
        }
        return result;
    }

    public static <T> String arrayToString(T[] a) {
        if (a == null) {
            return "[null]";
        }
        String result = "[";
        for (int i = 0; i < a.length; i++) {
            result += a[i].toString() + " ";
        }
        return result + "]";
    }

    /**
     * 
     * @param array nullable
     * @return
     */
    public static String arrayToString(String[] array) {
        if (array == null) {
            return "[null]";
        }
        String result = "";
        for (String s : array) {
            result += s + " ";
        }
        return result;
    }

    public static String arrayToString(int[] array) {
        String result = "";
        for (int s : array) {
            result += s + " ";
        }
        return result;
    }

    /**
     * convert float to String with two fractional digits
     * @param value
     * @return
     */
    public static String floatToString(float value) {
        if (Float.isNaN(value)) {
            return " --- ";
        }
        return String.format("%.2f", value);
    }
}

Related

  1. arrayToString(final String[] strs)
  2. arrayToString(final String[] value)
  3. arrayToString(final String[] values)
  4. arrayToString(final T... data)
  5. arrayToString(final T[] array)
  6. arrayToString(float[] arg)
  7. arrayToString(float[][] array)
  8. arrayToString(int[] ar)
  9. arrayToString(int[] arr)