In this example, we will create a function with Kotlin programming language which will return the total number of duplicate pair of numbers within a list. For example, if we enter [1,0,0,0] into that function it will return 1 because there is a pair of duplicate number within that list.

fun duplicates(array: IntArray): Int {
    var count = 0
    var find = array.toCollection(ArrayList())
    while(find.size > 0) {
        var search = find.removeAt(0)
        for(elem in find) {
            if(search == elem) {
                count = count + 1


    return count 

There you have it and welcome to the first article about Kotlin! I have started to study this new programming language and if you like Kotlin then don’t forget to subscribe to the Kotlin rss feed on the sidebar of this site. In the next chapter we will start to create an android application with Kotlin, if this is what you are looking for then do pay a visit to the Kotlin category on this website from time to time for a new article or just subscribe to the Kotlin rss feed as I have mentioned before.

Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *