How do I find duplicate values in two different arrays ?
Pseudo-code:
array1["a", "b", "c", "d"]
array2["b", "d", "e", "f"]
duplicatesFound = findDuplicates(array1, array2) //will return ["b", "d"]
How do I find duplicate values in two different arrays ?
Pseudo-code:
array1["a", "b", "c", "d"]
array2["b", "d", "e", "f"]
duplicatesFound = findDuplicates(array1, array2) //will return ["b", "d"]
obviously there is more than one way to solve it, here is one:
You can use Intersect between two Iterable
arrays. for example
val a1 = arrayListOf("a", "b", "c", "d")
val a2 = arrayListOf("b", "d", "e", "f")
val intersect = a2.intersect(a1)
Log.d(TAG,intersect.toString()) // prints [b,d]
Log.d(TAG,"${intersect.size}") // prints 2