当前位置:网站首页>OC-NSSet(集合)
OC-NSSet(集合)
2022-08-02 06:50:00 【彭同学她同桌】
与Array的区别
在内存中存储的方式是不连续的
在搜索一个个元素的时候效率更高 因为使用的是hash 比如说找一个元素 set通过hash算法可以直接找到 而Array就需要通过遍历
可以求交集并集
NSSet
初始化
NSSet*set = [[NSSet alloc]initWithObjects:@"a",@"b",nil];
NSSet*set2 = [set2 setWithArray]
查
if([set containsObject:@"a"])NSLog(@"YES");
求交集
//set(a,b,c). set2(a,s,d,)
if([set intersectsSet:set2])NSLog(@"YES");//求是否有相同元素
[set intersectSet:set2];
NSLog(@"%@",set);//a
求并集
//set(a,b,c). set2(a,s,d,)
[set unionSet:set2];//会将set2和se1中共同的都加到set中 会去重
NSLog(@“%@”,set);//a,b,c,s,d
求补集
//set(a,b,c). set2(a,s,d,)
[set minusSet:set2];
NSLog(@“%@”,set);//b,c
NSMutableSet
NSMutableSet*mset = [[NSMutableSet alloc]initWithCapacity:0];
[set addObject:@"a"];
边栏推荐
猜你喜欢
随机推荐
apt & apt-get命令
The second day HCIP
深度学习网络模型的改进与调整
【图像隐藏】基于matlab混合DWT-HD-SVD数字图像水印方法技术【含Matlab源码 2007期】
[npm install error report collection] - npm ERR! code ENOTEMPTY npm ERR! syscall rmdir
【机器学习】实验5布置:AAAI会议论文聚类分析
Leetcode Weekly 304
Wuhan 2022 organizing of the high-performance computing added new ecological development of high-performance computing
[Dataset][VOC] Eyewear dataset 6000 in VOC format
PWA 踩坑 - 第一次加载页面后无法获取CacheStorage某些资源
Revitalize rural circular economy and digital chain to link agricultural "ecological chain"
Clapper that can interact with the audience in real time
逆变器绝缘检测检测功能及软件实现
【暑期每日一题】洛谷 P1551 亲戚
CSRF-跨站请求伪造-相关知识
Vscode connect to remote server "Acquiring the lock on the/home / ~ 'problem
Gradle系列——Gradle插件(基于Gradle文档7.5)day3-2
August 2022 plan, focusing on ue4 video tutorials
数据库概论之MySQL表的增删改查1
自然语言处理 文本预处理(下)(张量表示、文本数据分析、文本特征处理等)








![(Part of it is not understood, and the notes are not completed) [Graph Theory] Difference Constraints](/img/e0/385579fc8657db8b175318bd739908.gif)
