Home How to check there's duplicate value in array or not?
Reply: 0

How to check there's duplicate value in array or not?

user892
1#
user892 Published in July 15, 2018, 9:12 pm
var arrEmails = NSMutableArray()
arrEmails = ["a.a@gmail.com", "a.a1@gmail.com", "a.a@gmail.com", "b.b@gmail.com", "c.c@gmail.com", "a.a1@gmail.com"]

above is my Array and i want to check is there any duplicate value or not. and for that i write below code.

let set = NSCountedSet.init(array: arrEmails as! [Any])
        var duplicates: Int = 0

        for var object in set {
            if set.count(for: object) > 1 {
                duplicates = duplicates+1
            }
        }

but in above code, if array contains values like below than it returns me duplicates value 1.

arrEmails = ["a.a@gmail.com", "", "", "b.b@gmail.com", "", ""]

I don't want to remove duplicate value, i just want to check number of duplicate value in array. How can check? please help me out.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.311805 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO