Java Array Output printArray(char[] array)

Here you can find the source of printArray(char[] array)

Description

print Array

License

Open Source License

Declaration

public static void printArray(char[] array) 

Method Source Code

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

public class Main {
    public static void printArray(char[] array) {
        StringBuilder buf = new StringBuilder();
        for (int i = 0; i < array.length; ++i) {
            if (i == 0) {
                buf.append("[");
                buf.append("'").append(array[i]).append("'");
            } else {
                buf.append(",");
                buf.append("'").append(array[i]).append("'");

            }/*www.  ja  v  a  2 s. co m*/

            if (i == array.length - 1) {
                buf.append("]");

            }

        }
        System.out.println(buf.toString());
    }

    public static String toString(String[] a) {
        StringBuilder buf = new StringBuilder();

        buf.append("[");
        if (a.length > 0) {
            buf.append("\"").append(a[0]).append("\"");
        }
        for (int i = 1; i < a.length; ++i) {
            String w = a[i];
            buf.append(", ").append("\"").append(w).append("\"");
        }
        buf.append("]");
        return buf.toString();
    }
}

Related

  1. printArray(double[] array)
  2. printArray(double[] array, String msgBefore, String msgAfter)
  3. printArray(double[][] in)
  4. printArray(double[][] in)