fill List with duplicate elements - Java java.util

Java examples for java.util:List Duplicate Element

Description

fill List with duplicate elements

Demo Code


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

import java.util.List;

public class Main {
    public static <A> List<A> fillList(int size, A item) {
        List<A> l = new ArrayList<A>(size);
        for (int i = 0; i < size; ++i)
            l.add(item);//w w w.  j a v a  2  s  .  c o  m
        return l;
    }
}

Related Tutorials