Here you can find the source of toString(int[] a, String separator, NumberFormat formatter)
Parameter | Description |
---|---|
a | The array to print. |
separator | A string to separate each element. |
formatter | A formatter to format the values. If null given the numbers will be printed raw. |
public static String toString(int[] a, String separator, NumberFormat formatter)
//package com.java2s; //License from project: Open Source License import java.text.NumberFormat; public class Main { /**//from w w w.j a v a 2 s . co m * @param a The array to print. * @param separator A string to separate each element. * @param formatter A formatter to format the values. If null given the numbers will be printed raw. * @return String representation of the given array. */ public static String toString(int[] a, String separator, NumberFormat formatter) { StringBuffer result = new StringBuffer(); if (formatter != null) { if (a.length > 0) result.append(formatter.format(a[0])); for (int i = 1; i < a.length; i++) result.append(separator).append(formatter.format(a[i])); } else { if (a.length > 0) result.append(a[0]); for (int i = 1; i < a.length; i++) result.append(separator).append(a[i]); } return result.toString(); } /** * @param a The array to print. * @param separator A string to separate each element. * @param formatter A formatter to format the values. If null given the numbers will be printed raw. * @return String representation of the given array. */ public static String toString(byte[] a, String separator, NumberFormat formatter) { StringBuffer result = new StringBuffer(); if (formatter != null) { if (a.length > 0) result.append(formatter.format(a[0])); for (int i = 1; i < a.length; i++) result.append(separator).append(formatter.format(a[i])); } else { if (a.length > 0) result.append(a[0]); for (int i = 1; i < a.length; i++) result.append(separator).append(a[i]); } return result.toString(); } /** * @param a The array to print. * @param separator A string to separate each element. * @param formatter A formatter to format the values. If null given the numbers will be printed raw. * @return String representation of the given array. */ public static String toString(double[] a, String separator, NumberFormat formatter) { StringBuffer result = new StringBuffer(); if (formatter != null) { if (a.length > 0) result.append(formatter.format(a[0])); for (int i = 1; i < a.length; i++) result.append(separator).append(formatter.format(a[i])); } else { if (a.length > 0) result.append(a[0]); for (int i = 1; i < a.length; i++) result.append(separator).append(a[i]); } return result.toString(); } /** * @param a The array to print. * @param separator A string to separate each element. * @return String representation of the given array. */ public static <T> String toString(T[] a, String separator) { StringBuffer result = new StringBuffer(); if (a.length > 0) result.append(a[0]); for (int i = 1; i < a.length; i++) result.append(separator).append(a[i]); return result.toString(); } }