'how to sort item of alphanumeric type of string using sort method in kotlin

This is my data

val data = ArrayList<Product>()
        data.add(Product(it=1,type = "Ait 45"))
        data.add(Product(it=2,type = "Ait 35"))
        data.add(Product(it=3,type = "Ait 65"))
        data.add(Product(it=4,type = "Ait 325"))
        data.add(Product(it=5,type = "Ait 42"))

I am trying sort data based on type in descending order which is string type

expected output after sort

data should = {(it=2,type = "Ait 35"),(it=5,type = "Ait 42"),(it=1,type = "Ait 45"),(it=3,type = "Ait 65"),(it=4,type = "Ait 325")}

Please help me how to sort item using sort method in kotlin



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source