Sorting a list based on another list's values - Java

后端 未结 5 967
梦如初夏
梦如初夏 2020-12-10 18:58

One list with names:(unsorted) e.g [paul, foul, mark]

Another list with integers: e.g [5, 2, 6]

The values on the secon

5条回答
  •  抹茶落季
    2020-12-10 19:10

    1. Build a list of pairs of (name, value) by taking elements from the two lists pairwise (having a class that stores the two values as fields). Implement Comparable to compare the value field.

    2. Sort the result with Collections.sort().

    3. Extract the names from the sorted list.

提交回复
热议问题