Create Collection of one element - Java java.util

Java examples for java.util:Collection Creation

Description

Create Collection of one element

Demo Code


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

import java.util.Collection;

import java.util.List;

public class Main {
    public static <T> Collection<T> toCollection(T element) {
        List<T> list = new ArrayList<T>(1);
        list.add(element);/*from  ww w.  ja  va 2s  . c  o  m*/
        return list;
    }
}

Related Tutorials