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?

Jack BeNimble
  • 35,733
  • 41
  • 130
  • 213
  • possible duplicate of [The best way to remove duplicate values from NSMutableArray in Objective-C?](http://stackoverflow.com/questions/1025674/the-best-way-to-remove-duplicate-values-from-nsmutablearray-in-objective-c) – lindinax Jan 20 '14 at 12:35

1 Answers1

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]);
   }

}

IHSAN KHAN
  • 97
  • 3