comparing facts,comparing怎么读
今天,在使用Stream排序时,出现了错误。 简单的记录,便于下一次检索
首先,按降序sort方法对list集合中对象的属性进行排序。 对于float getFollowDegree () )的返回值,查询出现后的排序顺序为降序(DESC,从大到小,reversed ) (如果没有方法,则为升序排序) ASC,从小到大。
对listResult进行排序,根据伴随度按降序排列flistfollowimsicollect=list result.stream (.sorted ) comparator.comparing ) followimsi336033
发生了以下问题。 如果要按降序排列followDegree,并且followDegree相等,则根据codeDaysThirsty的值按降序排列会自动将其加在后面.
//根据伴随度和30天的出现比率listfollowimsicollect1=list1. stream ().sorted ) comparator.com paring (follow imsi 3360: getfollowdect . tcodedaysthirsty ).reversed () (.collect ) collectors.tolist ) );
多数情况下,当然,从上述代码可以看出,将followDegree按降序排列,将codeDaysThirty按降序排列也没有问题.
其实,并非如此
需要的是,如果followDegree的值为降序,且值相等,则按降序执行codeDaysThirty。 因此,对上述代码的理解应为:
按codeDaysThirty降序排列,如果codeDaysThirty相等,则按followDegree排序。
因此,正确的代码是: //根据伴随度和30天的出现率,listfollowimsicollect1=list1. stream (.sorted ) comparator.comparing ) followimsi336033666必须是. thed dedaysthirsty ).reversed () ).collect ) collectors.tolist ) ); 请注意,getFollowDegree () (后面是reversed ) ) .
所以,甜甜的画板,明白其中的奥秘,从左到右运算