Java Collection to Array toStringArray(Collection collection)

Here you can find the source of toStringArray(Collection collection)

Description

to String Array

License

Open Source License

Declaration

static String[] toStringArray(Collection<?> collection) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class Main {
    private static final String[] EMPTY_STRING_ARRAY = new String[0];

    static String[] toStringArray(Collection<?> collection) {
        if (collection == null) {
            return null;
        }/*from  www . ja v  a2s  .c  om*/
        if (collection.isEmpty()) {
            return EMPTY_STRING_ARRAY;
        }
        List<String> list = new ArrayList<>(collection.size());
        for (Object o : collection) {
            list.add(o == null ? null : o.toString());
        }
        return list.toArray(new String[list.size()]);
    }
}

Related

  1. toLongArray(Collection collection)
  2. toLongArray(Collection collection)
  3. toStringArray(Collection collection)
  4. toStringArray(Collection collection)
  5. toStringArray(Collection collection)
  6. toStringArray(Collection collection)
  7. toStringArray(Collection collection)
  8. toStringArray(Collection collection)
  9. toStringArray(Collection collection)