public static <T> T[] toArray(Class<T> c, List<T> list)
  {
    @SuppressWarnings("unchecked")
    T[] ta= (T[])Array.newInstance(c, list.size());

    for (int i= 0; i<list.size(); i++)
      ta[i]= list.get(i);
    return ta;
  }
@Test
  public void testToArray() {

    //test a list of size 10
    List<Integer> list = new ArrayList<Integer>();

    for(int i=0; i<10; i++) {
      list.add(i);
    }

    Integer[] arr = GenericsUtil.toArray(list);

    for (int i = 0; i < arr.length; i++) {
      assertEquals(
              "Array has identical elements as input list",
              list.get(i), arr[i]);
    }
  }