Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    /**
     * a very space+time effectvie way to construct a (read-only) List of a repeated value.
     *
     * @param value the value we want repreated in a list
     * @param times the size of the desired list
     * @return a list containing <code>value</code> <code>times</code> times.
     */
    public static <T> List<T> repeat(final T value, final int times) {
        return new AbstractList<T>() {
            public T get(int i) {
                return value;
            }

            public int size() {
                return times;
            }
        };
    }
}