Java Array to String toStringArray(Object value)

Here you can find the source of toStringArray(Object value)

Description

Convert an Object array to a String array by invoking toString on each element

License

Open Source License

Parameter

Parameter Description
value a parameter

Return

String[]

Declaration

public static String[] toStringArray(Object value) 

Method Source Code

    //package com.java2s;
    /*/*from w ww.j a  v a  2s.c  om*/
     * Copyright (c) 2016 VMware, Inc. All Rights Reserved.
     *
     * This product is licensed to you under the Apache License, Version 2.0 (the "License").
     * You may not use this product except in compliance with the License.
     *
     * This product may include a number of subcomponents with separate copyright notices
     * and license terms. Your use of these subcomponents is subject to the terms and
     * conditions of the subcomponent's license, as noted in the LICENSE file.
     */

    import java.util.Arrays;

    public class Main {
        /**
         * Convert an Object array to a String array by invoking toString on each element
         *
         * @param value
         * @return String[]
         */
        public static String[] toStringArray(Object value) {
    if (value instanceof String[]) {
        // already a string array, just need a cast
        return (String[]) value;

    } else {
        // perform a toString on each element and return a new array
        Object[] valueArray = (Object[]) value;
        return Arrays.stream(valueArray)
                .map(o -> o.toString())
                .toArray(size -> new String[size]);
    }
}
    }

Related

  1. toString(T[] array, String prefix, String sep, String suffix)
  2. toStringArray(Collection strings)
  3. toStringArray(Dictionary props, String key, String[] defaultArray)
  4. toStringArray(final E[] array)
  5. toStringArray(int[] nums)
  6. toStringKeyValuePairs(Object[] keys, Object[] values, int size, StringBuilder dstOptional)
  7. toStrings(byte[] bytes)