java.util.Collections.checkedList() 方法


java.util.Collections.checkedList() 方法

package com.codingdict;

import java.util.*;

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

      // create arraylist       
      ArrayList<String> arlst=new ArrayList<String>();

      // populate the list
      arlst.add("TP");
      arlst.add("PROVIDES");
      arlst.add("QUALITY");
      arlst.add("TUTORIALS");

      // create typesafe view of the list
      Collection<String> tslst;
      tslst = Collections.checkedList(arlst,String.class);     

      System.out.println("Dynamically typesafe view is: "+tslst);
   }    
}