Java Array to String arrayToString(int[] array)

Here you can find the source of arrayToString(int[] array)

Description

array To String

License

Open Source License

Declaration

public static String arrayToString(int[] array) 

Method Source Code

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

public class Main {
    public static String arrayToString(int[] array) {
        StringBuilder output = new StringBuilder();
        for (int i = 0; i < array.length - 1; i++) {
            output.append(String.format("%d\t", array[i]));
        }/*from  ww w. j a  v  a 2 s.  c om*/
        output.append(String.format("%d", array[array.length - 1]));
        return output.toString();
    }

    public static String arrayToString(double[] array) {
        StringBuilder output = new StringBuilder();
        for (int i = 0; i < array.length - 1; i++) {
            output.append(String.format("%.2f\t", array[i]));
        }
        output.append(String.format("%.2f", array[array.length - 1]));
        return output.toString();
    }

    public static String arrayToString(double[] array, String format) {
        StringBuilder output = new StringBuilder();
        for (int i = 0; i < array.length - 1; i++) {
            output.append(String.format(format + "\t", array[i]));
        }
        output.append(String.format(format, array[array.length - 1]));
        return output.toString();
    }

    public static String arrayToString(double[] array, int digit) {
        StringBuilder output = new StringBuilder();
        for (int i = 0; i < array.length - 1; i++) {
            output.append(String.format("%." + digit + "f\t", array[i]));
        }
        output.append(String.format("%." + digit + "f", array[array.length - 1]));
        return output.toString();
    }
}

Related

  1. arrayToString(int[] ar)
  2. arrayToString(int[] arr)
  3. arrayToString(int[] arr)
  4. arrayToString(int[] arr)
  5. arrayToString(int[] array)
  6. arrayToString(int[] array)
  7. arrayToString(int[] array)
  8. arrayToString(int[] array)
  9. arrayToString(int[] array)