我有一组需要按照两个参数排序的项目列表,第一个参数是orderIndex,我已经成功地实现了它(请参见下面的代码),第二个参数是amount。因此,基本上第一项应该是具有最低orderIndex的项,并且它们需要按amount排序。
result.stream().sorted { s1, s2 -> s1.intervalType.orderIndex.compareTo(s2.intervalType.orderIndex) }.collect(Collectors.toList())
目前我有这段代码,它只按照orderIndex排序,第二个参数amount位于s1.item.amount。
有什么想法可以用第二个排序参数升级这个代码吗?
我找到了这个例子。
persons.stream().sorted(Comparator.comparing(Person::getName).thenComparing(Person::getAge));
我的问题是,如何访问Person对象中的其他对象。例如,在我正在排序的对象中有一个IntervalType对象,我需要使用intervalType.orderIndex。
注意:
只需注意,我需要在Kotlin中而不是Java中实现此功能。