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);

  • 相关阅读:
    MyBatis 框架系列之基础初识
    从零开始实现在线直播
    面试中关于Redis的问题看这篇就够了
    Spring Boot 中使用 MyBatis 整合 Druid 多数据源
    MyBatis的foreach语句详解
    小结:“服务器端跳转”和“客户端跳转”的区别
    Centos7.3安装vsftp服务
    Spring 注解@Value详解
    Spring中@Bean与@Configuration
    数据结构之LinkList
  • 原文地址:https://www.cnblogs.com/Azazqing/p/3696581.html
Copyright © 2011-2022 走看看