Java Collection to Array toArrayString(Collection col, boolean spacing)

Here you can find the source of toArrayString(Collection col, boolean spacing)

Description

to Array String

License

Open Source License

Declaration

public static String[] toArrayString(Collection<?> col, boolean spacing) 

Method Source Code

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

import java.util.Collection;
import java.util.Iterator;

public class Main {
    public static String[] toArrayString(Collection<?> col, boolean spacing) {
        int size = col.size();
        if (spacing) {
            size++;//  w  ww  . jav  a  2  s .co  m
        }
        String[] result = new String[size];
        int i = 0;
        if (spacing) {
            result[i++] = "";
        }
        Iterator<?> it = col.iterator();
        while (it.hasNext()) {
            result[i++] = it.next().toString();
        }
        return result;
    }
}

Related

  1. toArray(final Collection collection)
  2. toArray(java.util.Collection collection)
  3. toArray(T arrayOrCollection)
  4. toArrayInt(Collection integerCollection)
  5. toArrays(Collection strings)
  6. toBaseTypedCollection(Collection initial)
  7. toByteArray(Collection c)
  8. toByteArray(Collection c)
  9. toCharArray(Collection source)