Java Collections.nCopies(int n, T o)

Syntax

Collections.nCopies(int n, T o) has the following syntax.

public static <T> List <T> nCopies(int n,   T o)

Example

In the following code shows how to use Collections.nCopies(int n, T o) method.


/*from  ww w  .  j  av a2  s . c  o  m*/
import java.util.Collections;
import java.util.List;

public class Main {
   public static void main(String[] args) {
      // create a list with n copies 
      List<String> list = Collections.nCopies(5, "java2s.com");
      
      System.out.println(list);
   }      
}

The code above generates the following result.