• NSMutableArray(可变数组)(九)


    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

                                )*/

  • 相关阅读:
    SQL Server 2005的通用分页存储过程
    沉默的羔羊 赵传
    [转]Ubuntu 10.04 安装 codeblocks10.051 过程详细解析
    VMware7.1.5虚拟机安装Ubuntu 11.10使用share folders共享目录
    【转】libmemcached在windows下的PHP扩展(php_memcached.dll下载)
    Ubuntu升级之后The disk drive for / is not ready yet or not present的解决方法
    基于libmemcached,php扩展memcached的安装
    ubuntu configure的问题解决
    Ubuntu安装CodeBlocks相关问题(不能编译或者编译通过但不能生成可执行文件)
    ubuntu笔记
  • 原文地址:https://www.cnblogs.com/DevinSMR/p/5118592.html
Copyright © 2020-2023  润新知