//数组的创建 NSArray *array1 = [NSArray arrayWithObject:@"one"]; NSArray *array2 = [NSArray arrayWithObjects:@"one", @"two", nil]; NSArray *array3 = [NSArray arrayWithArray:array2]; NSArray *array4 = [[NSArray alloc] initWithArray:array1]; NSLog(@"%@, %@, %@, %@", array1, array2, array3, array4); //输出:one one,two one,two one //数组中元素的访问与个数 int count [array2 count]; //输出:count = 2 NSString *string1 = [array2 objectAtIndex:0]; //输出:string = one //追加数组中的内容 NSArray *array5 = [array2 arrayByAddingObject:@"end"]; //输出:array5 = one,two,end //数组->字符串 NSString *string2 = [array5 componentsJoinedByString:@","]; //输出:string2 = one,two,end //判断数组中是否存在一个指定的对象 BOOL isContain = [array5 containObject:@"end"]; //输出:isContain = 1 //根据指定的对象返回索引下标 NSInteger index = [array5 indexOfObject:@"end"]; //输出:index = 2 //返回数组中最后一个元素 NSString *lastObject = [array5 lastObject]; //输出:lastObject = end /*****************可变数组*******************/
cocoa foundation笔记-2,布布扣,bubuko.com
原文地址:http://my.oschina.net/Jacedy/blog/296931