Java Collections CheckedCollection()方法与示例
集合类的checkedCollection()方法 (Collections Class checkedCollection() method)
checkedCollection() Method is available in java.lang package.
DrawnCollection()方法在java.lang包中可用。
checkedCollection() Method is used to return the typesafe view of the given collection at runtime.
checkedCollection()方法用于在运行时返回给定集合的类型安全视图。
checkedCollection() 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.
checkedCollection()方法是一个静态方法,因此可以使用类名进行访问,如果我们尝试使用类对象访问该方法,则不会收到错误。
checkedCollection() Method does not throw an exception at the time of returning Collection.
返回Collection时, checkedCollection()方法不会引发异常。
Syntax:
句法:
public static Collection checkedCollection(Collection co, Class ele_ty);
Parameter(s):
参数:
Collection co – represent the collection for which to get a typesafe view at runtime.
集合co –表示在运行时为其获取类型安全视图的集合。
Class ele_ty – represent the element type that given collection is allowed to store.
ele_ty类 –表示允许给定集合存储的元素类型。
Return value:
返回值:
The return type of the method is Collection, it returns typesafe view of the given collection dynamically.
方法的返回类型为Collection ,它动态返回给定集合的typesafe视图。
Example:
例:
// Java Program is to demonstrate the example
// of Collection checkedCollection(Collection co, Class ele_ty) of
// Collections class
import java.util.*;
public class CheckedCollection {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 checkedCollection() method is to
// represent the type safe view of the given Collection
Collection < Integer > co = Collections.checkedCollection(link_list, Integer.class);
System.out.println();
System.out.println("Collections.checkedCollection(link_list, Integer.class) :");
// Display collection
System.out.println("co: " + co);
}
}
Output
输出量
link_list: [20, 10, 30, 40, 50]Collections.checkedCollection(link_list, Integer.class) :
co: [20, 10, 30, 40, 50]
翻译自: https://www.includehelp.com/java/collections-checkedcollection-method-with-example.aspx
Java Collections CheckedCollection()方法与示例相关推荐
- java rotate,Java Collections rotate()方法与示例
集合类rotate()方法rotation()方法在java.util包中可用. rotation()方法用于将List(l)元素旋转给定距离(dis). rotation()方法是静态方法,因此可以 ...
- Java Collections.emptyList() 方法的使用及注意事项
Java Collections.emptyList方法的使用及注意事项 一.emptyList() 作用:返回一个空的List(使用前提是不会再对返回的list进行增加和删除操作): 好处: 1. ...
- Java Collections.frequency()方法具有什么功能呢?
转自: Java Collections.frequency()方法具有什么功能呢? 下文笔者讲述Collections.frequency()方法的功能简介说明,如下所示: Collections. ...
- List元素互换,List元素转换下标,Java Collections.swap()方法实例解析
Java Collections.swap()方法解析 jdk源码: public static void swap(List<?> list, int i, int j) {// ins ...
- Java IOUtils.copy方法代码示例(亲测)
本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...
- java reverselist_Java Collections reverse()方法与示例
集合类reverse()方法reverse()方法在java.util包中可用. reverse()方法用于反转给定list(l)元素的顺序,换句话说,可以说此方法用于从右侧开始更改其元素的顺序. r ...
- java singletonlist_Java Collections singletonList()方法及示例
集合类singletonList()方法 (Collections Class singletonList() method) singletonList() method is available ...
- java user directory,Java ProcessBuilder directory()方法与示例
语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...
- Java序列化魔术方法及其示例使用
在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...
最新文章
- scala外部传入时间参数-亲测有效
- Robust line matching through line–point invariants
- Python 基础 —— str
- sqlserver Split 开放写法有兴趣的学习一下
- 写一个SFTP工具类实现连接
- Winhex的使用教程
- java vscode跳转类定义_快速使用 vscode 进行 Java 编程
- linux学习资料(转帖收藏)
- Excel数据透视表数据源自动更新方法
- 华为防火墙USG6309E开局基础配置之安全策略
- 信息传输速率与传信率_数据、信号、码元传输速率和信息传输速率等概念
- android开发接口调用,Android开发中webService接口调用示例
- Matlab中在哪hypot,c – 什么时候在`std :: sqrt(x * x y * y)’上使用`std :: hypot(x,y)“
- Spring Boot+JWT+Shiro+MyBatisPlus 实现 RESTful 快速开发后端脚手架!
- 移远EC25-xxx国外支持列表
- 基于esky实现python应用的自动升级
- vsCode安装使用教程和插件安装
- 中国大学MOOC消费者行为学考试题库(含答案)
- 趣学算法【第一章:算法之美】感悟(上)
- 公司开始走下坡路,如何保持个人能力的提升?