How to Find Duplicate Values in Arrays?

前端 未结 3 1664
栀梦
栀梦 2021-01-13 02:36

I am working on SQLite and I have written a query which returns me two arrays ItemsArray and CustomersIDArray as:

ItemsArray
Element at Index 0 = Off White,
         


        
3条回答
  •  花落未央
    2021-01-13 03:14

    Use NSCountedSet like below

    NSMutableArray *ary_res = [[NSMutableArray alloc] init];
        NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:@"11",@"13",@"34",@"9",@"13",@"34",@"9",@"2",nil];
        NSCountedSet *set = [[NSCountedSet alloc] initWithArray:array];
        for(id name in set)
        {
            if([set countForObject:name]==2)
                [ary_res addObject:name];
        }
        //
        NSLog(@"%@",ary_res);
    

提交回复
热议问题