This Java tutorial shows the quick and easy way to convert an array to a List in Java.
The Arrays class in the java.util package provides a utility method to convert an array to a List. The Arrays.asList() method will convert an array to a fixed size list. Below is sample code:
String[] array = { "a", "b", "c" };
List list = Arrays.asList(array);If you need to convert the array to an growable/expandable list, you can also convert it to either an ArrayList or a LinkedList. Below is an example of converting an array to an ArrayList and a LinkedList:
String[] array = { "a", "b", "c" };
List list = Arrays.asList(array);
ArrayList arrayList = new ArrayList(list);
LinkedList linkedList = new LinkedList(list);
1 comments:
Thanks knew there was something to do this
Cheers
Post a Comment