Java Number Format Pattern toString(int[] a, String separator, NumberFormat formatter)

Here you can find the source of toString(int[] a, String separator, NumberFormat formatter)

Description

to String

License

Open Source License

Parameter

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.

Return

String representation of the given array.

Declaration

public static String toString(int[] a, String separator, NumberFormat formatter) 

Method Source Code

//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();
    }
}

Related

  1. toAccountantFormat(String str, int scale)
  2. toDecimalFormat(BigDecimal value)
  3. toFormattedNumber(Object value)
  4. toNumber(String numString, String numFormatPattern)
  5. toNumberFormat(String input)
  6. toStringFormatted(byte[] bytes)
  7. unformatAmount(String formattedNumber)
  8. unformatingDecimalNumber(String cadena, Locale locale, int maxIntPart, int maxFloatPart)