Simplest way to sort list of objects

后端 未结 3 812
情话喂你
情话喂你 2021-02-12 17:40

I have a list of objects of type A. In a first iteration I assign each object a double value 0 < x < 1 and then want to sort each object according to it\'s x value.

<
3条回答
  •  囚心锁ツ
    2021-02-12 18:20

    Use tuples instead of creating a new wrapper class.

    List((1.2, "a1"), (0.1, "a2"), (0.9, "a3")).sorted
    // List((0.1,a2), (0.9,a3), (1.2,a1))
    

提交回复
热议问题