Write code to Convert an array to a list - Java java.util

Java examples for java.util:List Convert

Requirements

Write code to Convert an array to a list

Demo Code

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

import java.util.List;

public class Main {
    /**/*  ww w  .j a  v  a2 s  .  c  o  m*/
     * Convert an array to a list
     * @param array an array
     * @return List
     */
    public static <T> List<T> arrayToList(T array[]) {
        if (array != null) {
            List<T> list = new ArrayList<>();
            list.addAll(Arrays.asList(array));
            return list;
        }
        return null;
    }
}

Related Tutorials