//NSMutableArray 可变数组 可变数组继承不可变数组
//1.创建 设定元素个数进行创建
NSMutableArray *mutArr=[NSMutableArray arrayWithCapacity:7];
//2.向数组中添加一个元素
NSArray *[email protected][@"MON",@"TUE",@"WED",@"THU",@"FRI",@"SAT",@"SUN"];
NSMutableArray *mutWeek=[NSMutableArray arrayWithArray:week];
[mutWeek addObject:@"EIG"];
//3.指定下标插入
[mutWeek insertObject:@"NINE" atIndex:8];
//4.删除最后一个元素
[mutWeek removeLastObject];
for (id str in mutWeek) {
NSLog(@"%@",str);
}
//5.根据指定下标删除元素
[mutWeek removeObjectAtIndex:7];
//6.根据指定对象删除
[mutWeek removeObject:@"TEN"];
//7.替换指定小标元素
[mutWeek replaceObjectAtIndex:6 withObject:@"good"];
for (id str1 in mutWeek) {
NSLog(@"%@",str1);
}
时间: 2024-10-01 20:38:30