public static int[] toArray(List<Integer> list){
  if (list == null) {
    return null;
  }
  int length=list.size();
  int[] intArray=new int[length];
  for (int i=0; i < length; i++) {
    intArray[i]=list.get(i);
  }
  return intArray;
}

public static int [ ] toArray ( List < Integer > list ) { if ( list == null ) { return null ; } int length = list . size ( ) ; int [ ] intArray = new int [ length ] ; for ( int i = 0 ; i < length ; i ++ ) { intArray [ i ] = list . get ( i ) ; } return intArray ; }
converts a list of integers to a primitive array .
