1

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"]
1

1 Answer 1

2

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
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.