java 方法 示例_Java集合checkedList()方法与示例
java 方法 示例
集合類checkedList()方法 (Collections Class checkedList() method)
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 listlink_list.add(20);link_list.add(10);link_list.add(30);link_list.add(40);link_list.add(50);// Display LinkedListSystem.out.println("link_list: " + link_list);// By using checkedList() method is to // represent the type safe view of the given// Collection linked listCollection < Integer > co = Collections.checkedList(link_list, Integer.class);System.out.println();System.out.println("Collections.checkedList(link_list, Integer.class) :");// Display collectionSystem.out.println("co: " + co);} }Output
輸出量
link_list: [20, 10, 30, 40, 50]Collections.checkedList(link_list, Integer.class) : co: [20, 10, 30, 40, 50]翻譯自: https://www.includehelp.com/java/collections-checkedlist-method-with-example.aspx
java 方法 示例
總結
以上是生活随笔為你收集整理的java 方法 示例_Java集合checkedList()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: isinfinite_Java Doub
- 下一篇: Java类class isSynthet