Java Array to String arrayToString(String[] array)

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

Description

Convert an Array to a comma seperated String

License

Open Source License

Parameter

Parameter Description
array The array to be processed

Return

The Array with comma seperated elements

Declaration

public static String arrayToString(String[] array) 

Method Source Code

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

public class Main {
    /**/*  w ww  .j  a va  2s.c  o m*/
     * Convert an Array to a comma seperated String
     * @param array The array to be processed
     * @return The Array with comma seperated elements
     */
    public static String arrayToString(String[] array) {
        String output = "";
        for (int i = 0; i < array.length; i++) {
            if (output.equals("")) {
                output = output + array[i];
            } else {
                output = output + ", " + array[i];
            }
        }
        return output;
    }

    /**
     * Convert an Array to a comma seperated String, uses the method .toString()
     * @param array The array to be processed
     * @return The Array with comma seperated elements
     */
    public static String arrayToString(Object[] array) {
        String output = "";
        for (int i = 0; i < array.length; i++) {
            if (output.equals("")) {
                output = output + array[i];
            } else {
                output = output.toString() + ", " + array[i];
            }
        }
        return output;
    }

    /**
     * Convert an Array to a comma seperated String
     * @param array The array to be processed
     * @return The Array with comma seperated elements
     */
    public static String arrayToString(double[] array) {
        String output = "";
        for (int i = 0; i < array.length; i++) {
            if (output.equals("")) {
                output = output + array[i];
            } else {
                output = output + ", " + array[i];
            }
        }
        return output;
    }
}

Related

  1. arrayToString(String[] a, String delim)
  2. arrayToString(String[] a, String separator)
  3. arrayToString(String[] args, String delimiter)
  4. arrayToString(String[] arr)
  5. arrayToString(String[] arr, String expr)
  6. arrayToString(String[] array)
  7. arrayToString(String[] array)
  8. arrayToString(String[] array)
  9. arrayToString(String[] array)