Converting Array to List
Array can be converted to List by using asList static function of Arrays class.
Integer[] integerArray = {1,2,3,4};
List<Integer> integerList = Arrays.asList(integerArray);
Arrays.asList Returns a fixed-size list backed by the specified array.
public static List asList(T... a)
recall that argument list of variable length is implemented by packing the arguments into an array and passing that. It can be understood by the following example
List<Long> a = Arrays.asList(1L,2L,3L);
// is equivalent to
List<Long> b = Arrays.asList(new Long[]{1L,2L,3L});
October 22, 2008 | Filed Under Java
Related Post
Comments
Leave a Reply