Java Object Array to String objectArrayToStringArray(final Object[] objectArray)

Here you can find the source of objectArrayToStringArray(final Object[] objectArray)

Description

Converts an Object array to a String array (null-safe), by calling toString() on each element.

License

Apache License

Parameter

Parameter Description
objectArray the Object array

Return

the String array, or null if objectArray is null

Declaration

public static String[] objectArrayToStringArray(final Object[] objectArray) 

Method Source Code

//package com.java2s;
/*/*from   w  w  w.  ja v a  2 s  .  c  o  m*/
 * Copyright 2007 Kasper B. Graversen
 * 
 * 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 {
    /**
     * Converts an Object array to a String array (null-safe), by calling toString() on each element.
     * 
     * @param objectArray
     *            the Object array
     * @return the String array, or null if objectArray is null
     */
    public static String[] objectArrayToStringArray(final Object[] objectArray) {
        if (objectArray == null) {
            return null;
        }

        final String[] stringArray = new String[objectArray.length];
        for (int i = 0; i < objectArray.length; i++) {
            stringArray[i] = objectArray[i] != null ? objectArray[i].toString() : null;
        }

        return stringArray;
    }
}

Related

  1. objectArrayToString(Object[] arr, String name)
  2. objectArrayToString(Object[] objArray, String separator)
  3. objectArrayToString(Object[] objectArray)
  4. objectArrayToString(Object[] objects)
  5. objectArrayToString(String separator, Object... objects)
  6. objectArrayToStringArray(Object data[])
  7. objectArrayToStringArray(Object[] objectArray)
  8. objectArrayToStringArray(Object[] objs)
  9. objectArrayToStringArray(Object[][] objects)