I'm writing an android app using Kotlin. I have a mutable list of strings and I want to iterate through that list in order to combine the same strings and show how many times they appear in the same order. For example,
current list = [a,b,b,b,c,d,d,a,a,b,b,c]
I want the new list to look like this:
new list = [a,(b) 3 times,c,(d) 2 times,(a) 2 times,(b) 2 times,c]
I know I can do this using a for-each loop but I can't seem to think of how as I'm new to programming. Would really appreciate if someone could help me with this!