Java List Create createList(T value, int n)

Here you can find the source of createList(T value, int n)

Description

Creates a mutable list containing n copies of value.

License

Open Source License

Parameter

Parameter Description
T Type of list elements
value Basic value for list generation
n Number of copies

Return

A mutable list containing n copies of value

Declaration

public static <T> List<T> createList(T value, int n) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**/*  w ww  .ja  v a  2 s.  com*/
     * Creates a mutable list containing <code>n</code> copies of
     * <code>value</code>.
     * 
     * @param <T>
     *            Type of list elements
     * @param value
     *            Basic value for list generation
     * @param n
     *            Number of copies
     * @return A mutable list containing <code>n</code> copies of
     *         <code>value</code>
     */
    public static <T> List<T> createList(T value, int n) {
        List<T> result = new ArrayList<>(n);
        for (int i = 0; i < n; i++)
            result.add(value);
        return result;
    }
}

Related

  1. createList(List list)
  2. createList(Object... entries)
  3. createList(Object... objs)
  4. createList(Object[] values)
  5. createList(String s)
  6. createList(T... _entries)
  7. createList(T... array)
  8. createList(T... element)
  9. createList(T... items)