Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Collection; public class Main { public static long[] toPrimitive(Collection<Long> collection) { if (isEmpty(collection)) { return new long[0]; } long[] array = new long[collection.size()]; int i = 0; for (Long val : collection) { array[i] = val; i++; } return array; } public static boolean isEmpty(Collection collection) { return collection == null || collection.size() == 0; } }