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   w w w . j a  v  a 2  s.co  m
        return list;
    }
}

Related Tutorials