Here you can find the source of arrayToString(Object[] array)
Parameter | Description |
---|---|
array | the array to be converted to string. This argument can be null , in which case the string "null" is returned. |
public static String arrayToString(Object[] array)
//package com.java2s; //License from project: Apache License public class Main { private static final int EXPECTED_ELEMENT_STRING_LENGTH = 32; private static final String NULL_STR = "null"; /**/*from w ww . j a va 2 s .c o m*/ * Converts the specified array to a string. This methods works similar to * the {@code java.util.Arrays#toString(Object[])} but for arrays having * length of at least 2 returns a multi line string representation where * every element has its own dedicated line. This is intended to be more * readable for larger arrays. * * @param array the array to be converted to string. This argument can be * {@code null}, in which case the string "null" is returned. * @return the string representation of the passed array. This method never * returns {@code null}. * * @see #collectionToString(Collection) */ public static String arrayToString(Object[] array) { if (array == null) { return NULL_STR; } if (array.length == 0) { return "[]"; } else if (array.length == 1) { return "[" + array[0] + "]"; } else { StringBuilder result = new StringBuilder(EXPECTED_ELEMENT_STRING_LENGTH * array.length); result.append('['); for (int i = 0; i < array.length; i++) { result.append('\n'); result.append(array[i]); } result.append(']'); return result.toString(); } } }