Java Array Output printArray(Object[] in)

Here you can find the source of printArray(Object[] in)

Description

print Array

License

Apache License

Declaration

public static final String printArray(Object[] in) 

Method Source Code

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

public class Main {
    public static final String printArray(Object[] in) {
        if (in == null)
            return "null";
        String out = "";
        for (int i = 0; i < in.length; i++) {
            out += in[i].toString() + " ; ";
        }/*from   ww  w  .  ja v  a  2s  .c  om*/
        return out;
    }

    public static final String printArray(String[] in) {
        if (in == null)
            return "null";
        String out = "";
        for (int i = 0; i < in.length; i++) {
            out += in[i] + " ; ";
        }
        return out;
    }

    public static final String printArray(boolean[] in) {
        if (in == null)
            return "null";
        String out = "";
        for (int i = 0; i < in.length; i++) {
            if (in[i])
                out += "1 ; ";
            else
                out += "0 ; ";
        }
        return out;
    }

    public static final String printArray(byte[] in) {
        if (in == null)
            return "null";
        String out = "";
        for (int i = 0; i < in.length; i++) {
            out += in[i] + " ";
        }
        return out;
    }

    public static final String printArray(float[] in) {
        if (in == null)
            return "null";
        String out = "";
        for (int i = 0; i < in.length; i++) {
            out += in[i] + " ";
        }
        return out;
    }

    public static final String printArray(double[] in) {
        if (in == null)
            return "null";
        String out = "";
        for (int i = 0; i < in.length; i++) {
            out += in[i] + " ";
        }
        return out;
    }

    public static final String printArray(int[] in) {
        if (in == null)
            return "null";
        String out = "";
        for (int i = 0; i < in.length; i++) {
            out += in[i] + " ";
        }
        return out;
    }

    public static final String printArray(long[] in) {
        if (in == null)
            return "null";
        String out = "";
        for (int i = 0; i < in.length; i++) {
            out += in[i] + " ";
        }
        return out;
    }

    public static final String printArray(boolean[][] in) {
        if (in == null)
            return "null";
        String out = "";
        for (int i = 0; i < in.length; i++) {
            for (int j = 0; j < in[0].length; j++) {
                if (in[i][j])
                    out += "1  ";
                else
                    out += "0  ";
            }
            out += "\n";
        }
        return out;
    }

    public static final String printArray(byte[][] in) {
        if (in == null)
            return "null";
        String out = "";
        for (int i = 0; i < in.length; i++) {
            for (int j = 0; j < in[0].length; j++) {
                out += in[i][j] + " ";
            }
            out += "\n";
        }
        return out;
    }

    public static final String printArray(float[][] in) {
        if (in == null)
            return "null";
        String out = "";
        for (int i = 0; i < in.length; i++) {
            for (int j = 0; j < in[0].length; j++) {
                out += in[i][j] + " ";
            }
            out += "\n";
        }
        return out;
    }

    public static final String printArray(int[][] in) {
        if (in == null)
            return "null";
        String out = "";
        for (int i = 0; i < in.length; i++) {
            for (int j = 0; j < in[0].length; j++) {
                out += in[i][j] + " ";
            }
            out += "\n";
        }
        return out;
    }

    public static final String printArray(double[][] in) {
        return printArray(in, " ", "\n");
    }

    public static final String printArray(double[][] in, String colsep, String rowsep) {
        if (in == null)
            return "null";
        String out = "";
        for (int i = 0; i < in.length; i++) {
            for (int j = 0; j < in[0].length; j++) {
                out += in[i][j] + colsep;
            }
            out += rowsep;
        }
        return out;
    }

    public static final String printArray(float[][][] in) {
        if (in == null)
            return "null";
        String out = "";
        for (int k = 0; k < in[0][0].length; k++) {

            for (int i = 0; i < in.length; i++) {
                for (int j = 0; j < in[0].length; j++) {
                    out += in[i][j][k] + " ";
                }
                out += "\n";
            }
            out += "****************\n";
        }
        return out;
    }

    public static final String printArray(boolean[][][] in) {
        if (in == null)
            return "null";
        String out = "";
        for (int k = 0; k < in[0][0].length; k++) {

            for (int i = 0; i < in.length; i++) {
                for (int j = 0; j < in[0].length; j++) {
                    out += in[i][j][k] + " ";
                }
                out += "\n";
            }
            out += "****************\n";
        }
        return out;
    }

    public static final String printArray(int[][][] in) {
        if (in == null)
            return "null";
        String out = "";
        for (int k = 0; k < in[0][0].length; k++) {

            for (int i = 0; i < in.length; i++) {
                for (int j = 0; j < in[0].length; j++) {
                    out += in[i][j][k] + " ";
                }
                out += "\n";
            }
            out += "****************\n";
        }
        return out;
    }

    public static final String printArray(double[][][] in) {
        if (in == null)
            return "null";
        String out = "";
        for (int k = 0; k < in[0][0].length; k++) {

            for (int i = 0; i < in.length; i++) {
                for (int j = 0; j < in[0].length; j++) {
                    out += in[i][j][k] + " ";
                }
                out += "\n";
            }
            out += "****************\n";
        }
        return out;
    }

    public static final String[] toString(double[] a) {
        String[] b = new String[a.length];
        for (int i = 0; i < a.length; i++) {
            b[i] = Double.toString(a[i]);
        }
        return b;
    }

    public static final String[] toString(float[] a) {
        String[] b = new String[a.length];
        for (int i = 0; i < a.length; i++) {
            b[i] = Float.toString(a[i]);
        }
        return b;
    }
}

Related

  1. printArray(int[][] array, String arrayLabel, String rowLabel, String columnLabel)
  2. printArray(int[][] num)
  3. printArray(Object array)
  4. printArray(Object[] arry, String specialText)
  5. printArray(Object[] data)
  6. printArray(String lt, String[] arr, String rt)
  7. printArray(String name, int[] array)
  8. printArray(T[] array)
  9. printArrayOfUnknownObjectsOnePerLine(Object[] array)