HashSet, HashTable
HashTable 存储键值对 , Hashtable和Dictionary<TKey,TValue>都是存键值对
HashSet 只存储值,盛放不同的数据,相同的数据只保留一份
HashSet<T>对集合运算的操作
public void IntersectWithTest() {
HashSet<int> set1 = new HashSet<int>() { 1, 2, 3 };
HashSet<int> set2 = new HashSet<int>() { 2, 3, 4 };
set1.IntersectWith(set2); //取交集,结果赋值给set1
foreach (var item in set1) {
Console.WriteLine(item);
} //输出:2,3
}
同样,还有 并集UnionWith, 排除集 ExceptWith
.net 3.5为泛型集合提供了一系列的扩展方法,使得所有的泛型集合具备了set集合操作的能力
扩展方法
public void IntersectTest() {
HashSet<int> set1 = new HashSet<int>() { 1, 2, 3 };
HashSet<int> set2 = new HashSet<int>() { 2, 3, 4 };
IEnumerable<int> set3=set1.Intersect(set2);
foreach (var item in set1) { Console.WriteLine(item); }
foreach (var item in set3) { Console.WriteLine(item); }
//输出:o //set1 : 1,2,3 //set3 : 2,3
}
IEnumerable<T> 其他的扩展方法也是一样,都是不改变调用方法的数组,而是产生并返回新的IEnumerable<T>接口类型的数组
HashSet<T>是一个Set集合,查询上有较大优势,但无法通过下标方式来访问单个元素
HashSet, HashTable的更多相关文章
- HashSet HashTable 与 TreeSet
HashSet<T>类 HashSet<T>类主要是设计用来做高性能集运算的,例如对两个集合求交集.并集.差集等.集合中包含一组不重复出现且无特性顺序的元素. HashSet& ...
- HashSet HashTable HashMap的区别 及其Java集合介绍
(1)HashSet是set的一个实现类,hashMap是Map的一个实现类,同时hashMap是hashTable的替代品(为什么后面会讲到). (2)HashSet以对象作为元素,而HashMap ...
- HashSet HashTable HashMap的区别
(1)HashSet是set的一个实现类,hashMap是Map的一个实现类,同时hashMap是hashTable的替代品(为什么后面会讲到). (2)HashSet以对象作为元素,而HashMap ...
- ArrayList,Vector,HashMap,HashSet,HashTable之间的区别与联系
在编写java程序中,我们最常用的除了八种基本数据类型,String对象外还有一个集合类,在我们的的程序中到处充斥着集合类的身影!java中集合大家族的成员实在是太丰富了,有常用的ArrayList. ...
- LinkedList,ArrayList,Vector,HashMap,HashSet,HashTable之间的区别与联系
在编写java程序中,我们最常用的除了八种基本数据类型,String对象外还有一个集合类,在我们的的程序中到处充斥着集合类的身影!java中集合大家族的成员实在是太丰富了,有常用的ArrayList. ...
- HashMap,HashSet,HashTable,LinkedHashMap,LinkedHashSet,ArrayList,LinkedList,ConcurrentHashMap,Vector 区别
ConcurrentHashMap是弱一致性,也就是说遍历过程中其他线程可能对链表结构做了调整,因此get和containsKey返回的可能是过时的数据 ConcurrentHashMap是基于分段锁 ...
- HashMap, HashTable,HashSet,TreeMap 的时间复杂度
hashSet,hashtable,hashMap 都是基于散列函数, 时间复杂度 O(1) 但是如果太差的话是O(n) TreeSet==>O(log(n))==> 基于树的搜索,只需要 ...
- HashTable, HashSet, HashMap的区别
HashTable, HashSet, HashMap的区别 hash是一种很常见也很重要的数据结构,是用hash函数根据键值(key)计算出存储地址,以便直接访问.由完美hash函数(即键值 ...
- Basic Tutorials of Redis(3) -Hash
When you first saw the name of Hash,what do you think?HashSet,HashTable or other data structs of C#? ...
随机推荐
- 洛谷P4556 雨天的尾巴 线段树
正解:线段树合并 解题报告: 传送门! 考虑对树上的每个节点开一棵权值线段树,动态开点,记录一个max(num,id)(这儿的id,define了一下,,,指的是从小到大排QAQ 然后修改操作可以考虑 ...
- 集合求交集 & 去除列表中重复的元素
集合求交集: set1 = {1,2,3,4,5} set2 = {4,5,6,7,8} 交集:set3 = set1 & set2 print(ste3) #结果为{4,5} 或者ste1. ...
- javascript替代Array.prototype.some操作
Array.prototype.some在低版本浏览器好像不太兼容,下列是替代方法 一. for 循环 const initIds: any[] = [1,2,3]; const Ids: any[] ...
- 七、Spring Boot 启动配置原理
几个重要的事件回调机制 配置在META-INF/spring.factories ApplicationContextInitializer SpringApplicationRunListener ...
- rem : web app适配的秘密武器
css html { font-size: calc(100vw / 3.75) } jsdocument.documentElement.style.fontSize = $(document.do ...
- vue package-lock.json的作用
其实用一句话来概括很简单,就是锁定安装时的包的版本号,并且需要上传到git,以保证其他人在npm install时大家的依赖能保证一致.
- 016-插件使用-head
一.安装以及概览 elasticsearch-head将是一款专门针对于elasticsearch的客户端工具 elasticsearch-head配置包,下载地址:https://github.co ...
- zha男/女的三种境界
本文为chedan贴,谈一谈找对象时渣男/女的三种表现,分别对应三种境界,涉世未深的男生女生可加以小心,自身属于zha类型的可略过本文. 另,本文的恋爱观基于两个原则.一是对象应是从朋友到恋人的 ...
- Sublime Text 许可证
----- BEGIN LICENSE Alexander Single User License EA7E- 51F47F09 4EAB1285 7827EFF0 8B1207DC A76A6EA3 ...
- [LeetCode] 441. Arranging Coins_Easy tag: Math
You have a total of n coins that you want to form in a staircase shape, where every k-th row must ha ...