Here you can find the source of arrayToString(String[] array)
public static String arrayToString(String[] array)
//package com.java2s; //License from project: Apache License import java.text.DecimalFormat; import java.text.NumberFormat; public class Main { protected static final NumberFormat formatter = new DecimalFormat("###.###"); public static String arrayToString(String[] array) { if (array.length == 0) { return "[]"; }/* w w w . ja v a 2s .com*/ StringBuilder str = new StringBuilder(); str.append("[").append(array[0]); for (int i = 1; i < array.length; i++) { str.append(" ").append(array[i]); } str.append("]"); return str.toString(); } public static String arrayToString(double[] array) { if (array.length == 0) { return "[]"; } StringBuilder str = new StringBuilder(); str.append("[").append(formatDouble(array[0])); for (int i = 1; i < array.length; i++) { str.append(", ").append(formatDouble(array[i])); } str.append("]"); return str.toString(); } public static String arrayToString(float[] array) { if (array.length == 0) { return "[]"; } StringBuilder str = new StringBuilder(); str.append("[").append(formatDouble(array[0])); for (int i = 1; i < array.length; i++) { str.append(", ").append(formatDouble(array[i])); } str.append("]"); return str.toString(); } public static String arrayToString(int[] array) { if (array.length == 0) { return "[]"; } StringBuilder str = new StringBuilder(); str.append("[").append(formatDouble(array[0])); for (int i = 1; i < array.length; i++) { str.append(", ").append(formatDouble(array[i])); } str.append("]"); return str.toString(); } public static String formatDouble(double value) { return formatter.format(value); } public static String formatDouble(double value, int n) { StringBuilder str = new StringBuilder("###."); for (int nn = 0; nn < n; nn++) { str.append("#"); } NumberFormat newFormatter = new DecimalFormat(str.toString()); return newFormatter.format(value); } }