1,不可变数组:类:NSArry
//对象初始化方法
1> NSArray *arr1 = [[NSArray alloc]initWithObjects:@”one”,@”two”,@”three”,@”four” ,nil];
NSLog(@”%@”,arr1);
/*结果:(
one,
two,
three,
four
)
*/
//类方法:( 即直接用类调用方法。)指定若干对象生成方法
2> NSArray *arr3 = [NSArray arrayWithObjects:@”one”,@”two”,@”three”,@”four” , nil];
//类方法:使用已经存在的数组生成新数组,相当于复制
3> NSArray *arr2 = [[NSArray alloc]initWithArray:arr1];
NSArray *arr2 = [NSArray arrayWithArray:arr1];
//获取数组的元素的个数
//对象方法
4> NSUInteger count = [arr3 count];
//从数组中获取单个元素
//注意:在不知道什么类型的时候可以用id类型
5> id obj = [arr3 objectAtIndex:2];//id是通用指针类型
//数组元素拼接成字符串
6> NSString *str = [arr1 componentsJoinedByString:@"*"];//数组的元素用什么连接
NSLog(@"%@",str);//结果:one*two*three*four
//字符串元素根据什么分开存到数组中,用这个方法componentsSeparatedByString
7> NSString *arr4 = [str componentsSeparatedByString:@"*"];