Suppose I have an ArrayList of String and an ArrayList of int.
My ArrayList of Strings contains:
index : value
-----------------
0 : "Paul"
1 : "Peter"
2 : "Maria"
My ArrayList of Integers contians:
index : value
-----------------
0 : 2
1 : 0
2 : 1
Suppose I sort my int array using
Collections.sort(myArrayOfint);
The result should be 0 at index 0, 1 at index 1, and 2 at at index 2 right?
What I want to do is sort my String array taking in consideration my int Array’s new order, so for example “Paul” would go to index 1, “Peter” to index 2, and “Maria” to index 0. The order would be swapped same as my int array.
How can I do this, is it possible?
You can create class with the properties and use different
Comparators that compares based on different properties: