Return | Method | Summary |
---|---|---|
static<T> List<T> | nCopies(int n, T o) | Returns an immutable list consisting of n copies of the specified object. |
Create List containing n Copies of Specified Object
import java.util.Collections;
import java.util.List;
public class Main {
public static void main(String[] args) {
List list = Collections.nCopies(5, "java2s.com");
System.out.println("List contains, ");
System.out.println(list);
}
}
The output:
List contains,
[java2s.com, java2s.com, java2s.com, java2s.com, java2s.com]
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |