I have a list of strings like this :-
listOf("abc", "a", "bb", "aa", "aaa", "bb", "a")
I want an output like this :-
listOf("a", "a", "aa", "bb", "bb", "aaa", "abc")
First I want to sort list by length and then again sort that length group by letters.
I tried below code so far
fun main() {
val result = listOf("abc", "a", "bb", "aa", "aaa", "bb", "a").groupBy { it.length }
val valueList = ArrayList(result.values).flatMap { it.toList() }
println(valueList)
}
But the result I got is like below
[abc, aaa, a, a, bb, aa, bb]
After @Sergey Lagutin's duplication comment I also tried
val sortedList = a.sortedWith(compareBy { it.length })
Which is not returning the desired result