Creating n copies of the specified object

Returning an immutable list consisting of n copies of the specified object. The newly allocated data object is tiny (it contains a single reference to the data object). This method is useful in combination with the List.addAll method to grow lists. The returned list is serializable.

package collection.demos;



import java.util.Collections;

import java.util.List;



public class NewClass {

    public static void main(String[] args) {

        List<String> items=null;

        items=Collections.nCopies(10"test");

        for (String string : items) {

            System.out.println(string);

        }

    }

}

No comments:

Popular Posts