小总结:数组,集合,字典

数组:
NSArray *array2 = [NSArray arrayWithObject:@"one"];//只有一个元素的数组
NSArray *array3 = [NSArray arrayWithObjects:@"one", @"two", @"three", nil];//有多个元素的数组
NSArray *array4 = @[@"one", @"two", @"three"];//优化后的方法,最常用的
NSArray *array5 = [NSArray arrayWithArray:array4];//生成数组的副本

NSMutableArray *array1 = [NSMutableArray array];//空数组,有意义
NSMutableArray *array2 = [NSMutableArray arrayWithCapacity:100];//预估值
NSMutableArray *array4 = [NSMutableArray arrayWithObjects:@"one", @"two", @"three", nil];//标准方法,最常用的
集合:
NSSet *set1 = [NSSet setWithObjects:@"one",@"two",@"three",@"two", nil];//标准创建方法
NSSet *set2 = [NSSet setWithSet:set1];//副本创建
NSArray *str = @[@"one",@"two",@"three",@"two"];
NSSet *set3 = [NSSet setWithArray:str];//数组转换成集合

NSMutableSet *set1 = [NSMutableSet set];//空集合,有意义
NSMutableSet *set2 = [NSMutableSet setWithCapacity:100];//预估值100,不是上限,突破后效率会降低
NSMutableSet *set3 = [NSMutableSet setWithObjects:@"1",@"2",@"3", nil];//创建集合的同时初始化```

####字典:

NSDictionary dic1 = [NSDictionary dictionaryWithObjectsAndKeys:@"one",@"1"/先写值,后写关键字/,@"two",@"2", nil];//创建字典的标准方法
NSDictionary
dic2 = @{@"1":@"one",@"2":@"two"};//优化方法,最常用
NSArray a1 = @[@"one",@"two",@"three"];
NSArray
a2 = @[@"1",@"2",@"3"];
NSDictionary dic3 = [NSDictionary dictionaryWithObjects:a1 forKeys:a2];//将数组转换成字典,两个数组的关键字和值必须对应
NSDictionary
dic4 = [NSDictionary dictionaryWithDictionary:dic3];//创建字典的副本

NSMutableDictionary dict1 = [NSMutableDictionary dictionary];//空字典,有意义,可以添加键值对
NSMutableDictionary
dict2 = [NSMutableDictionary dictionaryWithCapacity:100];//预估值创建
NSMutableDictionary *dict3 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"one",@"1",@"two",@"2",@"three",@"3", nil];//存储在堆上;标准方法
```

转载于:https://www.cnblogs.com/xulinmei/p/7420081.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值