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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/545531.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

算法设计TSP问题动态规划

#include <iostream> #include <cmath> using namespace std; //集合虚拟化用000 、001 、010 、011 、100 、101 、110 、111分别表示{} 、{1}&#xff08;V[2^(1-1)]&#xff09; 、{2}&#xff08;V[2^(2-1)]&#xff09; 、{1,2}&#xff08;V[2^(1-1)2^(2-1)]…

Oracle 练习题 20131021 for 循环练习

--Oracle 练习题 20131021 for 循环练习--1、用for循环实现一个倒置的乘法表。beginfor i in reverse 1 .. 9 loopfor j in reverse 1 .. i loopdbms_output.put(i || x || j || || i * j || );end loop;dbms_output.put_line();end loop;end;--2、打印1-100之间所有的素数。…

字符串使用与内部实现原理

Redis 发展到现在已经有 9 种数据类型了&#xff0c;其中最基础、最常用的数据类型有 5 种&#xff0c;它们分别是&#xff1a;字符串类型、列表类型、哈希表类型、集合类型、有序集合类型&#xff0c;而在这 5 种数据类型中最常用的是字符串类型&#xff0c;所以本文我们先从字…

Lisp-Stat翻译 —— 第九章 统计绘图窗体

2019独角兽企业重金招聘Python工程师标准>>> 第九章 统计绘图窗体 除了前几章略述的绘图窗体原型提供的基本绘图工具之外&#xff0c;Lisp-Stat里的统计绘图还需要用来管理数据和将那些数据转换成屏幕上的图形的工具集。这些工具由绘图原型graph-proto提供。更多的…

Java ClassLoader getSystemResource()方法与示例

ClassLoader类getSystemResource()方法 (ClassLoader Class getSystemResource() method) getSystemResource() method is available in java.lang package. getSystemResource()方法在java.lang包中可用。 getSystemResource() method is used to find the system resource of…

操作系统(王道笔记第三章内存)

第三章内存3.1_1内存的基础知识&#xff08;1&#xff09;什么是内存&#xff1a;略&#xff08;2&#xff09;进程运行的基本原理①从写程序到程序运行②链接③装入3.1_2内存管理的概念&#xff08;1&#xff09;内存管理管哪几个方面&#xff08;2&#xff09;内存保护①上下…

按钮button加超链接

突然想做一个普通按钮&#xff0c;然后让按钮超链接到别的页面&#xff0c;不知道怎么搞&#xff0c;不过还是在百度找到了。1.如果让本页转向新的页面则用&#xff1a;<input typebutton οnclick"window.location.href(连接)"> 2.如果需要打开一个新的页面进…

Redis 快速搭建与使用

Redis 是由 C 语言开发的开源内存数据存储器&#xff0c;经常被用作数据库、缓存以及消息队列等。 Redis 因为其强大的功能和简洁的设计&#xff0c;深受广大开发者和公司的喜爱&#xff0c;几乎占领了内存数据库市场的所有份额。 1 Redis 特性 Redis 有很多优秀的特性&#…

如何计算Python中列表项的出现次数?

The python count() method counts the number of occurrences of an element in the list and returns it. python count()方法对列表中某个元素的出现次数进行计数并返回它。 Syntax: 句法&#xff1a; list.count(x)The count() method takes a single argument, x, whose…

网页自动关闭的代码

<script language"javascript">window.openernull; window.open(, _self, );//模拟自己打开自己window.close();//再关闭就没有对话框了</script>--------------------------以下是过多少秒自动关闭网页,弹窗<html><head><title>JS定时…

hibernate annotation注解方式来处理映射关系

2019独角兽企业重金招聘Python工程师标准>>> 在hibernate中&#xff0c;通常配置对象关系映射关系有两种&#xff0c;一种是基于xml的方式&#xff0c;另一种是基于annotation的注解方式&#xff0c;熟话说&#xff0c;萝卜青菜&#xff0c;可有所爱&#xff0c;每个…

操作系统Ubuntu(实验一二)

摘录&#xff1a;https://www.cnblogs.com/penglang14/p/10632360.html 实验一二1.1_小技巧1.2_ls查看目录命令1.3_cd切换目录命令1.4_查看文件内容命令(1)cat filename(2)more filename(3)head [-n] filename([]表示此内容可有可无)&#xff08;4&#xff09;wc命令确定行数、…

Redis 是如何执行的?

在以往的面试中&#xff0c;当问到一些面试者&#xff1a;Redis 是如何执行的&#xff1f;收到的答案往往是&#xff1a;客户端发命令给服务器端&#xff0c;服务端收到执行之后再返回给客户端。然而对于执行细节却「避而不谈」 &#xff0c;当继续追问服务器端是如何执行的&am…

java 枚举迭代_Java中的枚举和迭代器之间的区别

java 枚举迭代Java中的枚举与迭代器 (Enumeration vs Iterator in Java) Here, we will see how Enumeration differs from Iterator? 在这里&#xff0c;我们将看到Enumeration与Iterator有何不同&#xff1f; 1)枚举 (1) Enumeration) Enumeration is an interface which i…

ORA-14551: 无法在查询中执行 DML 操作

最近在调试一个带DML操作的函数时&#xff0c;一直不成功&#xff0c;在PL/SQL中测试时没问题&#xff0c;通过SQL语句调用函数时就不行了&#xff0c;刚开始一直没找到原因&#xff0c;后来无意间把 函数中捕获异常的代码注释掉&#xff0c;终于通过SQL调试时&#xff0c;弹出…

第五章I/O管理

I/O章节5.1.1I/O分类&#xff08;1&#xff09;按使用特性分&#xff08;2&#xff09;I/O设备按传输速率分类&#xff08;3&#xff09;I/O设备按信息交换的单位分5.1.2I/O控制器5.1.3I/O控制方式&#xff08;1&#xff09;程序直接控制方式&#xff08;轮询&#xff09;&…

阿里巴巴分布式服务框架 Dubbo

1.Dubbo是阿里巴巴内部的SOA服务化治理方案的核心框架&#xff0c;每天为2000 个服务提供3,000,000,000 次访问量支持&#xff0c;并被广泛应用于阿里巴巴集团的各成员站点。Dubbo自2011年开源后&#xff0c;已被许多非阿里系公司使用。 2.入门文档 http://alibaba.github.io/d…

列表使用与内部实现原理

列表类型 (List) 是一个使用链表结构存储的有序结构,它的元素插入会按照先后顺序存储到链表结构中,因此它的元素操作 (插入\删除) 时间复杂度为 O(1),所以相对来说速度还是比较快的,但它的查询时间复杂度为 O(n),因此查询可能会比较慢。 1 基础使用 列表类型的使用相对来…

c ++查找字符串_C ++类和对象| 查找输出程序| 套装1

c 查找字符串Program 1: 程序1&#xff1a; #include <iostream>using namespace std;class Sample {privateint A;privateint B;publicvoid init(){A 10;B 20;}publicvoid print(){cout << A << " " << B;}};int main(){Sample S;S.init…

Oracle 练习P297 131026 PL/SQL块程序

--1、编写一个PL/SQL块&#xff0c;输出所有员工的员工姓名&#xff0c;员工号、工资和部门号。beginfor v_emp in (select * from emp) loopdbms_output.put(员工姓名&#xff1a; || v_emp.ename);dbms_output.put(&#xff0c;员工号&#xff1a; || v_emp.empno);dbms_outp…