首页 > 编程语言 > 详细

NSMutableArray(可变数组)(九)

时间:2016-01-10 17:03:25      阅读:158      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!