Here you can find the source of arrayToString(final Object[] array)
Parameter | Description |
---|---|
array | the array of objects to represent |
public static final String arrayToString(final Object[] array)
//package com.java2s; /******************************************************************************* * Copyright 2014 Tiese Barrell/*from w w w. ja va 2 s. com*/ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ public class Main { private static final String NULL_VALUE = "<null>"; private static final String ARRAY_START = "{"; private static final String ARRAY_END = "}"; private static final String ARRAY_SEPARATOR = ", "; /** * Provides a string representation of the provided array of objects. * * @param array * the array of objects to represent * @return a string representation of the objects */ public static final String arrayToString(final Object[] array) { final StringBuilder builder = new StringBuilder(); builder.append(ARRAY_START); if (array != null && array.length > 0) { appendNonEmptyArrayToString(array, builder); } builder.append(ARRAY_END); return builder.toString(); } private static void appendNonEmptyArrayToString(final Object[] array, final StringBuilder builder) { for (int i = 0; i < array.length; i++) { final String toAppend = array[i] == null ? NULL_VALUE : array[i].toString(); builder.append(toAppend); if (i != array.length - 1) { builder.append(ARRAY_SEPARATOR); } } } }