Variable group Nsmutablearray

Source: Internet
Author: User

  //Nsmutablearray inherit to Nsarray//Nsarray * array = @[]; //1. Creating a mutable arrayNsmutablearray * array = [[Nsmutablearray alloc] Initwithcapacity:0]; //adding elements to an array dynamically using AddObject        /*[Array addobject:@ "one"];        [Array addobject:@ ""];        [Array addobject:@ "three"];         [Array addobject:@ "one"]; */NSString* STR1 =@" One"; NSString* STR2 =@" Both"; NSString* STR3 =@"three"; //The array can be stored in the same object multiple times[Array addobject:str1];        [Array addobject:str2];        [Array ADDOBJECT:STR3];                [Array addobject:str1]; //2. Specify where the object is inserted[Array insertobject:str1 Atindex:2]; //3. Delete objects that will delete all the same addresses in the array through the object[Array removeobject:str1]; //4. Deleting an object by index, exceeding the count value of the array, results in an exception of index beyond bounds[Array Removeobjectatindex:0];        [Array addobject:str2];        [Array ADDOBJECT:STR3];                [Array addobject:str1]; //5. Delete all elements in the array[Array removeallobjects]; NSLog (@"Array%@", array);        [Array addobject:str2];        [Array ADDOBJECT:STR3];            [Array addobject:str1]; //1.for Swapping Traversal         for(inti =0; i < Array.count; i++) {NSString* str =[Array objectatindex:i]; //do not add or remove elements to the array when iterating over the array.//[Array removeobject:str1];NSLog (@"Str%@", str); }                        //2. Enhanced for Loop         for(NSString * STRinchArray) {//[Array removeobject:str1]; //If you delete an element in the enhanced for loop, it will directly cause an exception to appearNSLog (@"Str%@", str); }                //3. EnumeratorsNsenumerator* Enumerator =[Array objectenumerator]; NSString*value;  while(Value =[Enumerator Nextobject]) {            //If you delete the element in the enumerator, it will directly cause the exception to appear//[Array removeobject:str1];NSLog (@"Str%@", value); }                        //4. How to determine which element to delete by traversingNsmutablearray* Array2 =[[Nsmutablearray alloc] init]; [Array2 AddObject:@"1"]; [Array2 AddObject:@"2"]; [Array2 AddObject:@"3"]; [Array2 AddObject:@"4"]; [Array2 AddObject:@"5"]; Nsmutablearray* TMP =[[Nsmutablearray alloc] init];  for(NSString * STRincharray2) {            if([str isequaltostring:@"3"]) {[TMP addobject:str]; }} NSLog (@"array2%@", array2); NSLog (@"tmp%@", TMP); //iterating through a temporary array         for(inti =0; i < Tmp.count; i++) {NSString* str =[tmp objectatindex:i]; //deleted from the original array, objects stored in the temporary array[Array2 Removeobject:str]; } NSLog (@"array2%@", array2);

Variable group Nsmutablearray

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.