I assume that your values all belong to each other like in a table, for example:
| name | age | score
------------------------------
index 0 | a | 2 | 3
index 1 | b | 3 | 4
index 2 | c | 5 | 4
index 3 | a | 6 | 1
and you want to sort it by the score column.
There are multiple approaches to solve this issue, so I will show my favorite one below.
Using a data class
Declare the data class
For this purpose, it would be good to declare a simple data class that acts as a wrapper around the three variables. (You could also use the predefined Kotlin class Triple)
data class User(val name: String, val age: Int, val score: Int)
... creates a simple data class that fits your needs. Each instance of the data class
represents the values of all three array lists at one index (one row on the table above).
Convert the lists
To convert your three lists to an instance of the User class, you can use the Kotlin extension function mapIndexed which transforms a list into a list of another type while providing us with the elements and its index, which we need to access the proper values in the other lists.
val users = name.mapIndexed { index, value -> User(value, age[index], score[index]) }
Now we have a list of users that looks like this:
[User(name=a, age=2, score=3), User(name=b, age=3, score=4), User(name=c, age=5, score=4), User(name=a, age=6, score=1)]
Sort the list
And we can now simply append the sortedByDescending function to order sort it in descending order:
val usersSorted = name.mapIndexed { index, value -> User(value, age[index], score[index]) }.sortedByDescending { it.score }
It is always best practice to use classes if you want to store more than two values of an object, especially in this case.
Go back to the original lists
If you (somehow) still need the original lists, you can get them back by using the map function. But please note that this form of data isn't very handy.
val name = users.map { it.name }
val age = users.map { it.age }
val score = users.map { it.score }
name,age, andscoreproperties) and then sort that list. You can then convert that sorted list of objects back to three separate lists if you want.