Java Array to String arrayToStringNullable(String[] a)

Here you can find the source of arrayToStringNullable(String[] a)

Description

transforms an array of strings to string with removed null elements.

License

Open Source License

Parameter

Parameter Description
a a parameter

Declaration

public static String arrayToStringNullable(String[] a) 

Method Source Code

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

public class Main {
    /**//from w  w  w .ja v  a 2s.co m
     * transforms an array of strings to string with removed null elements.
     * @param a
     * @return
     */
    public static String arrayToStringNullable(String[] a) {
        if (a == null) {
            return "[]";
        }

        int iMax = a.length - 1;
        if (iMax == -1) {
            return "[ ]";
        }

        StringBuilder b = new StringBuilder();
        b.append('[');
        for (int i = 0;; i++) {
            if (a[i] == null) {
            } else {
                b.append(String.valueOf(a[i]));
            }
            if (i == iMax) {
                return b.append(']').toString();
            }
            if (a[i + 1] == null) {
                //b.append(',');
                b.append(' ');
            } else {
                //b.append(", ");
                b.append(' ');
            }
        }
    }
}

Related

  1. arrayToString(T[] array, CharSequence start, CharSequence end)
  2. arrayToString(T[] items, String delimiter)
  3. arrayToString2D(String title, String innerTitle, double[][] vect)
  4. arrayToStringArray(boolean[] values)
  5. arrayToStringDelimited(final String[] array, final String delimiter)
  6. arrayToStrings(String[] s, String delimiter)
  7. arrayToStringWithDifferenceOrientedFormat(double[] values, int minDigits)
  8. arrayToStringWithPrefix(T[] array, String splitter, String prefix)
  9. asString(final String[] array)