Java Array Output printArray(String name, int[] array)

Here you can find the source of printArray(String name, int[] array)

Description

print Array

License

Apache License

Declaration

public static void printArray(String name, int[] array) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String DEFAULT_DOUBLE_FORMAT = "%f";

    public static void printArray(String name, int[] array) {
        Integer[] temp = new Integer[array.length];
        for (int i = 0; i < array.length; i++)
            temp[i] = Integer.valueOf(array[i]);
        printArray(name, temp);//from w  ww .j  a  va2 s.  c om
    }

    public static void printArray(String name, long[] array) {
        Long[] temp = new Long[array.length];
        for (int i = 0; i < array.length; i++)
            temp[i] = Long.valueOf(array[i]);
        printArray(name, temp);
    }

    public static void printArray(String name, double[] array) {
        printArray(name, array, DEFAULT_DOUBLE_FORMAT);
    }

    public static void printArray(String name, double[] array, String format) {
        Double[] temp = new Double[array.length];
        for (int i = 0; i < array.length; i++)
            temp[i] = Double.valueOf(array[i]);
        printArray(name, temp, format);
    }

    public static void printArray(String name, boolean[] array) {
        Boolean[] temp = new Boolean[array.length];
        for (int i = 0; i < array.length; i++)
            temp[i] = Boolean.valueOf(array[i]);
        printArray(name, temp);
    }

    public static <T> void printArray(String name, T[] array) {
        printArray(name, array, null);
    }

    public static <T> void printArray(String name, T[] array, String format) {
        StringBuilder sb = new StringBuilder();
        sb.append(name);
        sb.append(": [");
        for (int i = 0; i < array.length; i++) {
            if (format == null)
                sb.append(array[i]);
            else
                sb.append(String.format(format, array[i]));
            if (i < array.length - 1)
                sb.append(", ");
        }
        sb.append("]");
        System.out.println(sb.toString());
    }
}

Related

  1. printArray(Object array)
  2. printArray(Object[] arry, String specialText)
  3. printArray(Object[] data)
  4. printArray(Object[] in)
  5. printArray(String lt, String[] arr, String rt)
  6. printArray(T[] array)
  7. printArrayOfUnknownObjectsOnePerLine(Object[] array)