zoukankan      html  css  js  c++  java
  • 可变数组 NSMutableArray

            //1.使用实例方法创建

            NSMutableArray *array3 = [[NSMutableArray alloc]initWithObjects:@"123", @"222", @"321", @"333", nil];

            NSLog(@"%@",array3);

            

            //2.使用类方法创建

            NSMutableArray *array4 = [NSMutableArray arrayWithObjects:@"789", @"888", @"999", @"987", nil];

            NSLog(@"%@",array4);

            

            //3.添加元素

            [array3 addObject:@"asdf"];

            NSLog(@"%@", array3);

            

            //4.插入元素

            [array4 insertObject:@"zzz" atIndex:1];

            NSLog(@"%@", array4);

            

            //5.删除元素

    //元素

            [array4 removeObject:@"zzz"];

            NSLog(@"%@", array4);       

    //下标

            [array4 removeObjectAtIndex:2];  

            NSLog(@"%@", array4);

            

            //6.替换元素

            [array3 replaceObjectAtIndex:2 withObject:@"SS"];

            NSLog(@"%@", array3);

            

            //7.交换指定位置的两个元素

            [array3 exchangeObjectAtIndex:1 withObjectAtIndex:2];

            NSLog(@"%@", array3);

            

            //8.根据对象来交换两个元素位置

            NSUInteger a = [array3 indexOfObject:@"SS"];

            NSUInteger b = [array3 indexOfObject:@"asdf"];

            [array3 exchangeObjectAtIndex:a withObjectAtIndex:b];

            NSLog(@"%@", array3);

  • 相关阅读:
    Javascript调用C#后台方法及JSon解析
    ul 仿 table 循环滚动
    windows服务
    simple demo how to get the list of online users
    IIS 4.0配置
    在线
    C学习笔记-多源文件的编译
    C学习笔记-多源文件的编译
    C学习笔记-函数
    C学习笔记-函数
  • 原文地址:https://www.cnblogs.com/Azazqing/p/3696581.html
Copyright © 2011-2022 走看看