本文共 2283 字,大约阅读时间需要 7 分钟。
java 方法 示例
checkedList() Method is available in java.lang package.
CheckedList()方法在java.lang包中可用。
checkedList() Method is used to return the typesafe view of the given List at runtime.
checkedList()方法用于在运行时返回给定List的类型安全视图。
checkedList() Method is a static method, so it is accessible with the class name and if we try to access the method with the class object then we will not get an error.
CheckedList()方法是静态方法,因此可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会收到错误。
checkedList() Method does not throw an exception at the time of returning validated List.
CheckedList()方法在返回经过验证的List时不会引发异常。
Syntax:
句法:
public static List checkedList(List l, Class ele_ty);
Parameter(s):
参数:
List l – represents the list for which to get typesafe view at runtime.
列表l –表示在运行时获取类型安全视图的列表。
Class ele_ty – represents the element type (ele_ty) that the given List is allowed to store.
ele_ty类 –表示允许存储给定List的元素类型(ele_ty)。
Return value:
返回值:
The return type of the method is List, it returns typesafe or validated view of the given List dynamically.
方法的返回类型为List ,它动态返回给定List的类型安全或经过验证的视图。
Example:
例:
// Java Program is to demonstrate the example// of List checkedList(List l, Class ele_ty) of Collections classimport java.util.*;public class CheckedList { public static void main(String args[]) { // Create a linked list object LinkedList < Integer > link_list = new LinkedList < Integer > (); // By using add() method is to add the // given elements in linked list link_list.add(20); link_list.add(10); link_list.add(30); link_list.add(40); link_list.add(50); // Display LinkedList System.out.println("link_list: " + link_list); // By using checkedList() method is to // represent the type safe view of the given // Collection linked list Collection < Integer > co = Collections.checkedList(link_list, Integer.class); System.out.println(); System.out.println("Collections.checkedList(link_list, Integer.class) :"); // Display collection System.out.println("co: " + co); }}
Output
输出量
link_list: [20, 10, 30, 40, 50]Collections.checkedList(link_list, Integer.class) :co: [20, 10, 30, 40, 50]
翻译自:
java 方法 示例
转载地址:http://jixzd.baihongyu.com/