Java Array to String toString(byte[] array)

Here you can find the source of toString(byte[] array)

Description

to String

License

Open Source License

Declaration


public static Object toString(byte[] array) 

Method Source Code

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

import java.util.Iterator;

public class Main {

    public static String toString(Object[] objects) {
        StringBuilder str = new StringBuilder();

        for (int i = 0; i < objects.length; i++) {
            str.append(objects[i]);/* ww w  . jav a  2  s  . c  om*/

            if (i != objects.length - 1)
                str.append(", ");
        }

        return str.toString();
    }

    public static Object toString(byte[] array) {
        StringBuilder str = new StringBuilder();

        for (int i = 0; i < array.length; i++) {
            str.append(array[i]);

            if (i != array.length - 1)
                str.append(", ");
        }

        return str.toString();
    }

    public static Object toString(char[] array) {
        StringBuilder str = new StringBuilder();

        for (int i = 0; i < array.length; i++) {
            str.append(array[i]);

            if (i != array.length - 1)
                str.append(", ");
        }

        return str.toString();
    }

    public static Object toString(short[] array) {
        StringBuilder str = new StringBuilder();

        for (int i = 0; i < array.length; i++) {
            str.append(array[i]);

            if (i != array.length - 1)
                str.append(", ");
        }

        return str.toString();
    }

    public static Object toString(int[] array) {
        StringBuilder str = new StringBuilder();

        for (int i = 0; i < array.length; i++) {
            str.append(array[i]);

            if (i != array.length - 1)
                str.append(", ");
        }

        return str.toString();
    }

    public static Object toString(long[] array) {
        StringBuilder str = new StringBuilder();

        for (int i = 0; i < array.length; i++) {
            str.append(array[i]);

            if (i != array.length - 1)
                str.append(", ");
        }

        return str.toString();
    }

    public static Object toString(float[] array) {
        StringBuilder str = new StringBuilder();

        for (int i = 0; i < array.length; i++) {
            str.append(array[i]);

            if (i != array.length - 1)
                str.append(", ");
        }

        return str.toString();
    }

    public static Object toString(double[] array) {
        StringBuilder str = new StringBuilder();

        for (int i = 0; i < array.length; i++) {
            str.append(array[i]);

            if (i != array.length - 1)
                str.append(", ");
        }

        return str.toString();
    }

    public static String toString(Iterator<?> iteration) {
        if (iteration == null)
            return "null";

        StringBuilder str = new StringBuilder();

        while (iteration.hasNext()) {
            str.append(iteration.next());

            if (iteration.hasNext())
                str.append(", ");
        }

        return str.toString();
    }
}

Related

  1. stringify(int arr[])
  2. stringify(int[] raw)
  3. toDelimitedString(Object[] array, String delimiter)
  4. toDelimitedString(Object[] array, String delimiter)
  5. toPrettyString(String[] array)
  6. toString(Class aClass, Object[] objects)
  7. toString(Class[] modelPath)
  8. toString(final byte[] buffer, final int offset, final int length)
  9. toString(final Object[] array)