1、
//NSMutableArray(可变数组) // NSMutableArray *marr2 = [[NSMutableArray alloc]initWithObjects:@"1",@"2",@"3" ,nil]; NSMutableArray *marr1 = [[NSMutableArray alloc]init];//因为是可变数组,这时只需要给一个空得数组即可,所以只用init //添加 [marr1 addObject:@"1"]; [marr1 addObject:@"22"]; [marr1 addObject:@"cc"]; NSLog(@"%@",marr1);/*2015-04-16 16:31:41.846 OCLesson4_NSString[2177:116050] ( 1, 22, cc )*/ |
2、
//删除,不能越界,越界即报错 [marr1 removeObjectAtIndex:0]; NSLog(@"%@",marr1);/*2015-04-16 16:32:46.124 OCLesson4_NSString[2188:116498] ( 22, cc )*/ |
3、
//插入,不能越界,越界即报错 [marr1 insertObject:@"aaa" atIndex:0]; NSLog(@"%@",marr1);/*2015-04-16 16:37:38.586 OCLesson4_NSString[2230:118462] ( aaa, 22, cc )*/ |
4、
//交换,不能越界,越界即报错 [marr1 exchangeObjectAtIndex:0 withObjectAtIndex:2]; NSLog(@"%@",marr1);/*2015-04-16 16:37:38.586 OCLesson4_NSString[2230:118462] ( cc, 22, aaa )*/ |
5、
//改,不能越界,越界即报错 marr1[0] = @"5"; NSLog(@"%@",marr1);/*2015-04-16 16:37:38.586 OCLesson4_NSString[2230:118462] ( 5, 22, aaa )*/ |