Here you can find the source of toPrimitivebyList(List
public static long[] toPrimitivebyList(List<Long> list)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { public static long[] toPrimitivebyList(List<Long> list) { int nullcounter = 0; for (Long l : list) { if (l == null) { nullcounter++;//from w w w.j a va2s . co m } } long[] result = new long[list.size() - nullcounter]; nullcounter = 0; for (int i = 0; i < list.size(); i++) { if (list.get(i) == null) { nullcounter++; } else { result[i - nullcounter] = list.get(i); } } return result; } }