I would like to determine the number of consecutive duplicate Strings in an ArrayList in Kotlin.
What I have is something along the lines of:
val array: ArrayList<String> = arrayListOf("training", "training", "assessment", "training", "assessment", "assessment")
Where the output I want is something that counts the consecutive duplicate elements like:
[["training", "2"], ["assessment", "1"], ["training", "1"], ["assessment", "2"]
or something simpler/cleaner.
I have found a similar solution in Python Counting consecutive duplicates of strings from a list. But I am looking for a Kotlin version. Thanks.