//1.創(chuàng)建一個(gè)空的可變數(shù)組
NSMutableArray*mArray1 = [[NSMutableArrayalloc]init];
NSMutableArray*mArray2 = [NSMutableArrayarray];
NSLog(@"mArray1 = %@",mArray1);
NSLog(@"mArray2 = %@",mArray2);
//2.把一個(gè)不可變的數(shù)組轉(zhuǎn)換成可變數(shù)組
NSArray*array =@[@"one",@"two",@"three"];
NSMutableArray*mArray3 = [[NSMutableArrayalloc]initWithArray:array];
NSLog(@"mArray3 = %@",mArray3);
NSMutableArray*mArray4 = [NSMutableArrayarrayWithArray:array];
NSLog(@"mArray4 = %@",mArray4);
//3.創(chuàng)建一個(gè)默認(rèn)有多個(gè)元素的可變數(shù)組
NSMutableArray*mArray5 = [[NSMutableArrayalloc]initWithObjects:@"1",@"2",@"3",@"4",nil];
NSMutableArray*mArray6 = [NSMutableArrayarrayWithObjects:@"a",@"b",@"c",@"a",nil];
NSLog(@"mArray5 = %@",mArray5);
NSLog(@"mArray6 = %@",mArray6);
/************增*************/
//1.添加元素(依此往后添加)
[mArray6addObject:@"d"];
NSLog(@"mArray6 = %@",mArray6);
//2.一次性添加多個(gè)元素[先把這些元素放入數(shù)組中侵歇,一次性添加]
NSArray*aa =@[@"SSY",@"2014"];
[mArray6addObjectsFromArray:aa];
NSLog(@"mArray6 = %@",mArray6);
//3.添加元素到指定的索引位置
[mArray6insertObject:@"xyz"atIndex:0];
NSLog(@"mArray6 = %@",mArray6);
/*************刪除****************/
//1.刪除單個(gè)元素
//[mArray6removeObject:@"a"];
//NSLog(@"mArray6 = %@",mArray6);
//2.刪除指定范圍的元素
NSRangerange = {2,3};
[mArray6removeObject:@"a"inRange:range];
NSLog(@"mArray6 = %@",mArray6);
//3.刪除索引位置對(duì)的元素
[mArray6removeObjectAtIndex:1];
NSLog(@"mArray6 = %@",mArray6);
//4.刪除數(shù)組中最后一個(gè)元素
[mArray6removeLastObject];
NSLog(@"mArray6 = %@",mArray6);
//5.全部刪除
[mArray6removeAllObjects];
NSLog(@"mArray6 = %@",mArray6);
/*************修改**************/
//1.交換數(shù)組中兩個(gè)索引對(duì)應(yīng)的元素
[mArray5exchangeObjectAtIndex:0withObjectAtIndex:mArray5.count-1];
NSLog(@"mArray5 = %@",mArray5);
//2.替換掉指定的索引對(duì)應(yīng)的元素
[mArray5replaceObjectAtIndex:1withObject:@"two"];
NSLog(@"mArray5 = %@",mArray5);
//3.重置數(shù)組
[mArray5setArray:@[@"sh",@"1992"]];
NSLog(@"mArray5 = %@",mArray5);