可变数组

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
//可变数组继承不可变数组
    //1.创建 设定元素个数进行创建
        NSMutableArray *arr=[NSMutableArray arrayWithCapacity:7];
    //2.想数组中添加一个元素
        NSArray *week=@[@"MON",@"TUE",@"WED",@"THU",@"FRI",@"SAT",@"SUN"];
        NSMutableArray *mutArr=[NSMutableArray arrayWithArray:week];
        [mutArr addObject:@"EIG"];
        for (id str in mutArr) {
            NSLog(@"%@",str);
        }
    //3.指定下标插入
        [mutArr insertObject:@"NINE" atIndex:8];
        for (id str in mutArr) {
            NSLog(@"%@",str);
        }
    //4.删除
        [mutArr removeLastObject];
        for (id str in mutArr) {
            NSLog(@"%@",str);
        }
    //5.根据指定对象进行删除
        [mutArr removeObject:@"SUN"];
        for (id str in mutArr) {
            NSLog(@"%@",str);
        }
    //6.根据制定下表删除
        [mutArr removeObjectAtIndex:5];
        for (id str in mutArr) {
            NSLog(@"%@",str);
        }

 

posted @ 2016-01-11 12:51  纽伦堡幅度  阅读(130)  评论(0编辑  收藏  举报