Mega Code Archive

 
Categories / Java / Class
 

ToString(Object[] array)

/* ------------------------------------------------------------------------  * $Id: ToString.java,v 1.1 2005/07/23 12:56:13 tpv Exp $  * Copyright 2005 Tim Vernum  * ------------------------------------------------------------------------  * 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.  * ------------------------------------------------------------------------  */ /**  * @version $Revision: 1.1 $  */ public final class ToString {     public static String toString(Object[] array)     {         StringBuffer buffer = new StringBuffer();         Class type = array.getClass().getComponentType();         if (type != Object.class)         {             buffer.append(type.getName());         }         if (array.length == 0)         {             buffer.append("[0]");         }         else         {             buffer.append("[");             buffer.append(array.length);             buffer.append("]{");             for (int i = 0; i < array.length; i++)             {                 buffer.append(array[i]);                 buffer.append(',');             }             buffer.setCharAt(buffer.length() - 1, '}');         }         return buffer.toString();     }     private ToString()     {         // Utility class     } }