NSMutableArray是属于NSArray的子类,又所有的NSArray方法,是一个可变数组
//
// main.m
// NSMutableArray
//
// Created by Rayln Guan on 9/5/13.
// Copyright (c) 2013 Rayln Guan. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
//申请一个空的array
NSMutableArray *arrTemp = [NSMutableArray array];
NSMutableArray *arr = [NSMutableArray arrayWithObjects:@"a",@"b",@"c",@"d",@"e", nil];
[arr addObject:@"e"]; //输出[a, b, c, d, e, e]
[arr removeObjectAtIndex:2]; //输出[a, b,d, e, e];
//会把所有e都移除掉!!
[arr removeObject:@"e"]; //输出[a, b, d]
[arr removeLastObject]; //输出[a, b]
[arr insertObject:@"n" atIndex:1]; //输出[a, n, b]
[arr replaceObjectAtIndex:2 withObject:@"c"];//输出[a, n, c]
[arr sortUsingSelector:@selector(compare:)]; //输出[a, c, n]
NSLog(@"%@", arr);
}
return 0;
}