Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,885 questions

51,811 answers

573 users

How to get unique values from two arrays in Kotlin

1 Answer

0 votes
fun get_unique_values(arr1: IntArray, arr2: IntArray): IntArray {
    val set1 = arr1.toSet()
    val set2 = arr2.toSet()

    val st = (set1 - set2) + (set2 - set1)
    
    return st.sorted().toIntArray()
}

fun main() {
    val arr1 = intArrayOf(1, 3, 6, 8, 12, 90)
    val arr2 = intArrayOf(2, 3, 5, 6, 7, 8, 96)

    val result = get_unique_values(arr1, arr2)
    println(result.joinToString(", "))
}


   
/*
run:

1, 2, 5, 7, 12, 90, 96
 
*/

 



answered Feb 17, 2025 by avibootz

Related questions

3 answers 88 views
1 answer 78 views
1 answer 93 views
2 answers 103 views
1 answer 109 views
1 answer 101 views
101 views asked Dec 9, 2024 by avibootz
...