Java tutorial
//package com.java2s; import java.util.Collection; import java.util.List; import java.util.Map; public class Main { public static long[] toLongArray(List<Long> list, long defaultValue) { if (isEmpty(list)) { return new long[0]; } long[] array = new long[list.size()]; for (int I = 0; I < list.size(); I++) { Long v = list.get(I); if (v == null) { array[I] = defaultValue; } else { array[I] = v.longValue(); } } return array; } public static boolean isEmpty(Collection<?> c) { return c == null || c.isEmpty(); } public static boolean isEmpty(Map<?, ?> map) { return map == null || map.isEmpty(); } @SafeVarargs public static <T> boolean isEmpty(T... array) { return array == null || array.length == 0; } }