Posted By

arunpjohny on 07/07/11


Tagged

java


Versions (?)

Converting a list into an array


 / Published in: Java
 

URL: http://download.oracle.com/javase/tutorial/reflect/special/arrayInstance.html

  1. public static <T> T[] convertToArray(List<T> values, Class<T> clazz) {
  2. Object object = Array.newInstance(clazz, values.size());
  3. for (int i = 0; i < values.size(); i++) {
  4. Array.set(object, i, values.get(i));
  5. }
  6.  
  7. @SuppressWarnings("unchecked")
  8. T[] array = (T[]) object;
  9. return array;
  10. }

Report this snippet  

You need to login to post a comment.