//1.创建一个集合(初始化集合对象)
NSArray *arr=[NSArray arrayWithObjects:@"zs",@"ls",@"ww", nil];
//2.集合元素个数
NSLog(@"%ld",arr.count);
//3.获取指定索引位置的集合元素
NSString *name=[arr objectAtIndex:0];
NSLog(@"%@",name);
//4.循环遍历集合 使用集合不能越界
for (int i=0; i<=arr.count; i++)
{
NSString *name1=[arr objectAtIndex:i];
NSLog(@"%@",name1);
}
//5.循环遍历 快速枚举
for (NSString *str in arr)
{
NSLog(@"%@",str);
}
//1.初始化可变集合
NSMutableArray *arr1=[NSMutableArray arrayWithCapacity:10];
//2.增加集合元素
[arr1 addObject:@"zs"];
[arr1 addObject:@"ls"];
//3.在指定位置插入集合
[arr1 insertObject:@"ww" atIndex:0];
NSLog(@"%@",arr1);
//4.把不可变集合转换为可变集合
NSMutableArray *test1=[NSMutableArray arrayWithCapacity:10];
NSArray *test2=@[@"a",@"e",@"c",@"d"];
[test1 addObjectsFromArray:test2];
//5.增加集合元素
[test1 addObject:@"f"];
NSLog(@"%@",test1);
//6.删除集合元素
[test1 removeObject:@"a"];
NSLog(@"%@",test1);
//7.将集合元素拼接为字符串
NSString *str11=[test1 componentsJoinedByString:@"+"];
NSLog(@"%@",str11);
//8.将字符串拆分为集合
NSArray *newarr=[str11 componentsSeparatedByString:@"-"];
NSLog(@"%@",newarr);