Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/yahibo/article/details/49445469
Programming the array in a relatively high frequency, a large amount of data processing are used in the array, the array is the number of the operation method
// 1.
Creating an array
NSMutableArray
* ARR = [
NSMutableArray
Array
];
NSMutableArray * of arr1 = [ NSMutableArray the arrayWithCapacity : 10];
NSMutableArray * arr2 is = [ NSMutableArray arrayWithObjects : @ ". 1" , @ "2" , @ ". 3" , nil ];
// * NSMutableArray arr3 = @ [@ "", @ "", @ ""]; // can not be created by this method is an array variable NSLog ( @ "% @" , ARR); // 2. deletions array [of arr1 addObject : @ "123" ];// At the end add an element of an array NSLog ( @ "% @"
, of arr1);
[of arr1 addObjectsFromArray : @ [ @ "456" , @ "456" ]]; // add to the plurality of array elements NSLog ( @ "% @" , of arr1); [of arr1 the insertObject : @ "789" atIndex : 0]; // add the elements in the specified location NSLog ( @ "% @" , of arr1); [of arr1 removeObject : @ "456" ]; // Removes the specified element NSLog ( @ "% @" , of arr1); [ arr1 removeAllObjects ];// remove all elements NSLog ( @ "% @"
, of arr1);
[of arr1 addObjectsFromArray : @ [ @ "123" , @ "456" , @ "789" , @ "369" , @ "258" , @ "147" ]]; // add elements NSLog ( @ " @% " , of arr1); [of arr1 removeObjectAtIndex : 0]; // Removes the specified location element NSLog ( @"% @ " , of arr1); [of arr1 replaceObjectAtIndex :. 1 withObject : @" 1475 " ];// the element at the location with ! "" Replace NSLog ( @ "% @"
, of arr1);
.. 3 // traverse // when traversing the array variable, not its CRUD NSArray * Ar = [ NSArray arrayWithArray : of arr1]; for ( NSString * S in Ar) { [of arr1 removeObject : @ "" ]; NSLog ( @ " enumeration -% @" , S); } // iterator enumerate an NSEnumerator * E = [of arr1 objectEnumerator ]; NSArray * AR1; the while (AR1 = [E NextObject ]) { NSLog ( @ "
Enumeration iterator -% @ " , AR1);
}
// Loop through for ( int I = 0; I <of arr1. COUNT ; I ++) { NSLog ( @" cycle enumeration -% @ " , of arr1 [I ]);
NSMutableArray * of arr1 = [ NSMutableArray the arrayWithCapacity : 10];
NSMutableArray * arr2 is = [ NSMutableArray arrayWithObjects : @ ". 1" , @ "2" , @ ". 3" , nil ];
// * NSMutableArray arr3 = @ [@ "", @ "", @ ""]; // can not be created by this method is an array variable NSLog ( @ "% @" , ARR); // 2. deletions array [of arr1 addObject : @ "123" ];// At the end add an element of an array NSLog ( @ "% @"
, of arr1);
[of arr1 addObjectsFromArray : @ [ @ "456" , @ "456" ]]; // add to the plurality of array elements NSLog ( @ "% @" , of arr1); [of arr1 the insertObject : @ "789" atIndex : 0]; // add the elements in the specified location NSLog ( @ "% @" , of arr1); [of arr1 removeObject : @ "456" ]; // Removes the specified element NSLog ( @ "% @" , of arr1); [ arr1 removeAllObjects ];// remove all elements NSLog ( @ "% @"
, of arr1);
[of arr1 addObjectsFromArray : @ [ @ "123" , @ "456" , @ "789" , @ "369" , @ "258" , @ "147" ]]; // add elements NSLog ( @ " @% " , of arr1); [of arr1 removeObjectAtIndex : 0]; // Removes the specified location element NSLog ( @"% @ " , of arr1); [of arr1 replaceObjectAtIndex :. 1 withObject : @" 1475 " ];// the element at the location with ! "" Replace NSLog ( @ "% @"
, of arr1);
.. 3 // traverse // when traversing the array variable, not its CRUD NSArray * Ar = [ NSArray arrayWithArray : of arr1]; for ( NSString * S in Ar) { [of arr1 removeObject : @ "" ]; NSLog ( @ " enumeration -% @" , S); } // iterator enumerate an NSEnumerator * E = [of arr1 objectEnumerator ]; NSArray * AR1; the while (AR1 = [E NextObject ]) { NSLog ( @ "
Enumeration iterator -% @ " , AR1);
}
// Loop through for ( int I = 0; I <of arr1. COUNT ; I ++) { NSLog ( @" cycle enumeration -% @ " , of arr1 [I ]);
}