Wednesday, May 6, 2015

Convert java array to collection list and vice versa

List and Set classes have toArray() method and Arrays class has toList() method.
Array.asList() copies array to List.

Below line of code convert Array object to List object.
String[] oa = new String[];
List cList = Arrays.asList(oa);


Below line of code convert List to Array object.
List cList = new ArrayList();
Object[] oa = cList.toArray();



No comments:

Post a Comment