集合
来源:互联网 发布:网络在线英语培训 编辑:程序博客网 时间:2024/05/17 08:38
// 无序对象集合 数据不能重复添加 NSSet *set = [[NSSet alloc]initWithObjects:@"one",@"two",@"three", @"four",@"five",@"one",nil]; // @"one"没有添加进去 NSLog(@"set = %@",set); // - (NSUInteger)countForObject:(id)object; NSMutableSet *mutableSet = [[NSMutableSet alloc]initWithObjects:@"one",@"two",@"three", @"four",@"five",@"one", nil]; // NSCountedSet *countSet = [NSCountedSet ]; // 长度 count set.count// NSUInteger count = [set count]; // 看是否包含某元素 BOOL isContain = [set containsObject:@"two"]; NSLog(@"是否包含--isCOntain:%d",isContain);// NSEnumerator *enumrator = []; // 添加值 [mutableSet addObject:@"six"]; NSLog(@"mutableSet = %@",mutableSet); // 删除值 [mutableSet removeObject:@"six"]; NSLog(@"mutableSet = %@",mutableSet); // 删除所有元素 [mutableSet removeAllObjects]; NSLog(@"mutableSet = %@",mutableSet); // 无序对象集合 数据不能重复添加 NSSet *set = [[NSSet alloc]initWithObjects:@"one",@"two",@"three", @"four",@"five",@"one",nil]; // @"one"没有添加进去 NSLog(@"set = %@",set);// If the same object appears more than once in the list, it is represented only once in the returned set. 如果相同的对象出现在这个列表中超过一次,那么它只会在返回的集合中表示一次 // - (NSUInteger)countForObject:(id)object; NSMutableSet *mutableSet = [[NSMutableSet alloc]initWithObjects:@"one",@"two",@"three", @"four",@"five",@"one", nil]; NSCountedSet *countSet = [[NSCountedSet alloc]initWithSet:mutableSet]; NSUInteger count = [countSet countForObject:@"one1"]; NSLog(@"count = %lu",count); // 长度 count set.count// NSUInteger count = [set count]; // 看是否包含某元素 BOOL isContain = [set containsObject:@"two"]; NSLog(@"是否包含--isContain:%d",isContain);// NSEnumerator *enumrator = []; // 添加值 [mutableSet addObject:@"six"]; NSLog(@"mutableSet = %@",mutableSet); // 删除值 [mutableSet removeObject:@"six"]; NSLog(@"mutableSet = %@",mutableSet); // 删除所有元素 [mutableSet removeAllObjects]; NSLog(@"mutableSet = %@",mutableSet); // 数组转化成集合 NSArray -> NSSet NSArray *array = @[@"one",@"two",@"three",@"four",@"five"]; NSSet *set = [NSSet setWithArray:array]; NSLog(@"set = %@",set); // 字典转化成数组 NSDictionary -> NSArray NSDictionary *dic = @{ @"name": @"Jack", @"age" : @"18", @"height":@"180" }; NSArray *keysArray = [dic allKeys]; NSArray *valuesArray = [dic allValues]; NSLog(@"keysArray = %@",keysArray); NSLog(@"valuesArray = %@",valuesArray); // 字符串转化成数组 NSString —> NSArray NSString *string = @"hello world Charles"; NSArray *strsArray = [string componentsSeparatedByString:@" "]; NSLog(@"%@",[strsArray objectAtIndex:0]); NSLog(@"%@",[strsArray objectAtIndex:1]); NSLog(@"strsArray = %@",strsArray);
0 0
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- http://www.gutirunhua.com/news/company/68.html
- socket编程<二>
- hdu 1023 Train Problem II (卡特兰数)
- 选择排序的几种算法
- sigprocmask阻塞信号
- 集合
- Nodejs 安装 grunt ,Webstorm grunt 配置
- http statusCode(状态码) 200、300、400、500序列
- Maven学习--------基础2
- freemarker 异常和错误显示
- 设计模式-工厂方法模式(Factory Method)
- Mac: Android studio+VirtualBox+Genymotion
- Swift学习笔记系列——(11)下标
- 去掉was管理控制台安全认证的方法