T[] array to List<T> - Java Collection Framework

Java examples for Collection Framework:List

Description

T[] array to List<T>

Demo Code


//package com.java2s;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static <T> List<T> toList(T[] elems) {
        ArrayList<T> list = new ArrayList<>();

        for (T elem : elems) {
            list.add(elem);//ww w.ja  v a 2 s.  c  o  m
        }

        return list;
    }
}

Related Tutorials