Java Set to String toStringArray(final Set set)

Here you can find the source of toStringArray(final Set set)

Description

Return a Set as a String array

License

Apache License

Parameter

Parameter Description
set a parameter

Declaration

public static String[] toStringArray(final Set<?> set) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class Main {
    /**/*from  w ww . ja  v  a2  s .  c  om*/
     * Return a Set as a String array
     * @param set
     * @return
     */
    public static String[] toStringArray(final Set<?> set) {
        final String[] f = new String[set.size()];
        int i = 0;
        for (final Iterator<?> iter = set.iterator(); iter.hasNext(); i++) {
            f[i] = iter.next().toString();
        }
        return f;
    }

    /**
     * Return a List as a String array
     * @param list
     * @return
     */
    public static String[] toStringArray(final List<?> list) {
        final String[] f = new String[list.size()];
        int i = 0;
        for (final Iterator<?> iter = list.iterator(); iter.hasNext(); i++) {
            f[i] = iter.next().toString();
        }
        return f;
    }
}

Related

  1. toString(Set attribute)
  2. toStringSet(String... metrics)