Here you can find the source of createList(T value, int n)
n
copies of value
.
Parameter | Description |
---|---|
T | Type of list elements |
value | Basic value for list generation |
n | Number of copies |
n
copies of value
public static <T> List<T> createList(T value, int n)
//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; } }