码迷,mamicode.com
首页 > 编程语言 > 详细

NSMutableArray(可变数组)(九)

时间:2016-01-10 17:06:37      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:

 

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

                            )*/

NSMutableArray(可变数组)(九)

标签:

原文地址:http://www.cnblogs.com/DevinSMR/p/5118592.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!