java.util.Collections.ncopies() 方法


java.util.Collections.ncopies() 方法

package com.codingdict;

import java.util.*;

public class CollectionsDemo {
   public static void main(String[] args) {

      // create a list with n copies
      List list = Collections.nCopies(5, "tuitorial Point");

      // create an iterator
      Iterator itr = list.iterator();

      System.out.println("Values are :");
      while (itr.hasNext()) {
         System.out.println(itr.next());
      }
   }      
}