Java Collection to Array collectionToArray(Collection collection)

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

Description

collection To Array

License

Open Source License

Declaration

@SuppressWarnings({ "rawtypes", "unchecked" })
public static Object[] collectionToArray(Collection collection) 

Method Source Code

//package com.java2s;

import java.util.Collection;

import java.util.Map;

public class Main {

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static Object[] collectionToArray(Collection collection) {
        Object[] objs = null;//  w  ww  .ja v a2 s .c  o m
        if (isNotEmpty(collection)) {
            objs = new Object[collection.size()];
            collection.toArray(objs);
        }
        return objs;

    }

    @SuppressWarnings("rawtypes")
    public static boolean isNotEmpty(Map map) {
        return !isEmpty(map);
    }

    @SuppressWarnings("rawtypes")
    public static boolean isNotEmpty(Collection collection) {
        return !isEmpty(collection);
    }

    public static boolean isNotEmpty(Object[] objs) {
        return !isEmpty(objs);
    }

    @SuppressWarnings("rawtypes")
    public static boolean isEmpty(Map map) {
        if (map == null || map.size() == 0) {
            return true;
        }
        return false;
    }

    @SuppressWarnings("rawtypes")
    public static boolean isEmpty(Collection collection) {
        if (collection == null || collection.size() == 0) {
            return true;
        }
        return false;
    }

    public static boolean isEmpty(Object[] objs) {
        if (objs == null || objs.length == 0) {
            return true;
        }
        return false;
    }
}

Related

  1. asArray(Collection c)
  2. asArray(Collection collection, E[] a)
  3. asBooleanArray(Collection collection)
  4. asLongArray(final Collection ls)
  5. asLongArray(java.util.Collection c)
  6. collectionToIntArray(Collection c)
  7. collectionToIntArray(final Collection numbers)
  8. collectionToObjectArray(Collection c)
  9. collectionToObjectArray(final Collection _list)