NSSet
来源:互联网 发布:0--100水仙花数java 编辑:程序博客网 时间:2024/05/18 22:45
// 使用便利构造器创建集合 NSSet *set1 = [NSSet setWithObjects:@"qqq", @"www", @"qqq", nil]; NSLog(@"%@", set1); // 使用数组创建集合 NSArray *arr1 = [NSArray arrayWithObjects:@"12", @"23", @"12", nil]; NSSet *set2 = [NSSet setWithArray:arr1]; NSLog(@"%@", set2); // 打印集合元素个数 NSLog(@"set2 count = %ld", [set2 count]); // 创建空的可变集合// NSMutableSet *mutableSet = [NSMutableSet set]; NSMutableSet *mutableSet1 = [NSMutableSet setWithSet:nil]; // 添加两个不同元素 [mutableSet1 addObject:@"55"]; [mutableSet1 addObject:@"45"]; [mutableSet1 addObject:@"55"]; [mutableSet1 addObjectsFromArray:@[@"ww", @"ww"]]; NSLog(@"%@", mutableSet1); // 删除元素 [mutableSet1 removeObject:@"45"]; NSLog(@"%@", mutableSet1); //NSCountedSet // 通过集合计算重复元素的个数 NSArray *ages = @[@13, @(23), @23, @12, @12, @12, @34, @345, @34, @23, @23]; NSCountedSet *agesSet = [NSCountedSet setWithArray:ages]; // 获取重复对象的个数 NSUInteger count = [agesSet count]; NSLog(@"count = %lu", count); NSUInteger count1 = [agesSet countForObject:@23]; NSLog(@"23 = %lu", count1); NSUInteger count2 = [agesSet countForObject:@12]; NSLog(@"12 = %lu", count2); // 快速遍历 for (NSNumber *number in ages) { NSLog(@"%@", number); }
0 0
- Nsset
- NSSet
- NSSet
- NSSet
- NSSet
- NSSet
- NSSet
- NSSet
- NSSet
- nsset
- NSSet
- NSSet
- NSSet
- NSSet详解
- NSSet详解
- NSSet 札记
- NSSet sort
- NSSet、NSMutableSet
- Unity3D 上传日志
- .net经典解读(事件和委托)
- 通过vagrant打造php虚拟机通用环境
- pmap
- Android线程间通信--Handler
- NSSet
- MyBatis Annotation配置
- 二、我们应当怎样做需求调研:初识
- C# List多字段排序
- 工业相机编程模型和流程
- 三、我们应当怎样做需求调研:拜访
- 5.20 一个混合算法与面向对象思想的例子
- vim
- CodeForces 66D--思维(yy)