0

I have an NSMutableArray that I'd like to check for duplicate strings. I don't need to know what the strings are, just if there are any duplicates.

I'm thinking add the answers to an NSSet, then check to see if the number of entries is different than the original array. Is there a better way to do this?

1

1 Answer 1

3

Here is the code to see duplicates values

for(int j = 0; j < [myMutableArray count]; j++){
      for( k = j+1;k < [myMutableArray count];k++){
       NSString *str1 = [myMutableArray objectAtIndex:j];
       NSString *str2 = [myMutableArray objectAtIndex:k];
       if([str1 isEqualToString:str2])
           NSLog(@"duplicate value is %@",[myMutableArray objectAtIndex:k]);
   }

}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.