概述
标题和内容同时进行排序:
duplicates= duplicates.stream().sorted(Comparator.comparing(Duplicates::getTitleSimilarity,Comparator.reverseOrder()).thenComparing(Duplicates::getContentSimilarity,Comparator.reverseOrder())).collect(Collectors.toList());
duplicates= duplicates.stream().sorted(Comparator.comparing(Duplicates::getTitleSimilarity,Comparator.reverseOrder()).thenComparing(Duplicates::getContentSimilarity,Comparator.reverseOrder())).collect(Collectors.toList());
//列表先按标题相似度降序,再按内容相似度降序
duplicates.stream().sorted(Comparator.comparing(Duplicates::getTitleSimilarity).thenComparing(Comparator.comparing(Duplicates::getContentSimilarity).reversed()).reversed()).collect(Collectors.toList());
同时进行俩个参数排序
duplicates.stream().sorted(Comparator.comparing(Duplicates::getContentSimilarity).reversed());
也可以不使用流进行直接排序
duplicates.sorted(Comparator.comparing(Duplicates::getContentSimilarity).reversed());
//列表先按标题相似度降序,再按内容相似度降序
duplicates.stream().sorted(Comparator.comparing(Duplicates::getTitleSimilarity).thenComparing(Comparator.comparing(Duplicates::getContentSimilarity).reversed()).reversed()).collect(Collectors.toList());
duplicates.stream().sorted(Comparator.comparing(Duplicates::getContentSimilarity).reversed());
duplicates.sort(Comparator.comparing(Duplicates::getTitleSimilarity));
duplicates.sort(Comparator.comparing(Duplicates::getContentSimilarity));
排序结果:
列表先按标题相似度降序,再按内容相似度降序 [
Duplicates(id=1181588929369, title=测试数据库1, contentSimilarity=0.9392675375220804, titleSimilarity=0.704608271645791),
Duplicates(id=1181588929369, title=测试数据库2, contentSimilarity=0.5006453224425479, titleSimilarity=0.4638740932635561),
Duplicates(id=1181588929369, title=测试数据库0, contentSimilarity=0.8890708399644924, titleSimilarity=0.2732442258286829),
Duplicates(id=1181588929369, title=测试数据库3, contentSimilarity=0.643501300281883, titleSimilarity=0.15838141373838144),
Duplicates(id=1181588929369, title=测试数据库4, contentSimilarity=0.5543713310795758, titleSimilarity=0.007959455923802206)]
列表先按标题相似度降序,再按内容相似度降序 [
Duplicates(id=1181588929369, title=测试数据库3, contentSimilarity=0.18791019480704962, titleSimilarity=0.8685129378947092),
Duplicates(id=1181588929369, title=测试数据库2, contentSimilarity=0.15739413084569576, titleSimilarity=0.6418851598988512),
Duplicates(id=1181588929369, title=测试数据库0, contentSimilarity=0.38574966906668706, titleSimilarity=0.3832292382442515),
Duplicates(id=1181588929369, title=测试数据库1, contentSimilarity=0.9848937962794468, titleSimilarity=0.2854683355507478),
Duplicates(id=1181588929369, title=测试数据库4, contentSimilarity=0.7670096858650658, titleSimilarity=0.05295739543192157)]
列表先按标题相似度降序,再按内容相似度降序 [
Duplicates(id=1181588929369, title=测试数据库1, contentSimilarity=0.9392675375220804, titleSimilarity=0.704608271645791),
Duplicates(id=1181588929369, title=测试数据库2, contentSimilarity=0.5006453224425479, titleSimilarity=0.4638740932635561),
Duplicates(id=1181588929369, title=测试数据库0, contentSimilarity=0.8890708399644924, titleSimilarity=0.2732442258286829),
Duplicates(id=1181588929369, title=测试数据库3, contentSimilarity=0.643501300281883, titleSimilarity=0.15838141373838144),
Duplicates(id=1181588929369, title=测试数据库4, contentSimilarity=0.5543713310795758, titleSimilarity=0.007959455923802206)]
列表先按标题相似度降序,再按内容相似度降序 [
Duplicates(id=1181588929369, title=测试数据库3, contentSimilarity=0.18791019480704962, titleSimilarity=0.8685129378947092),
Duplicates(id=1181588929369, title=测试数据库2, contentSimilarity=0.15739413084569576, titleSimilarity=0.6418851598988512),
Duplicates(id=1181588929369, title=测试数据库0, contentSimilarity=0.38574966906668706, titleSimilarity=0.3832292382442515),
Duplicates(id=1181588929369, title=测试数据库1, contentSimilarity=0.9848937962794468, titleSimilarity=0.2854683355507478),
Duplicates(id=1181588929369, title=测试数据库4, contentSimilarity=0.7670096858650658, titleSimilarity=0.05295739543192157)]
最后
以上就是温婉鸡为你收集整理的JAVA集合类进行ListJDK8 的流stream排序List.stream().sorted(Comparator.comparing().thenComparing(Comparator.标题和内容同时进行排序: //列表先按标题相似度降序,再按内容相似度降序 同时进行俩个参数排序也可以不使用流进行直接排序排序结果:的全部内容,希望文章能够帮你解决JAVA集合类进行ListJDK8 的流stream排序List.stream().sorted(Comparator.comparing().thenComparing(Comparator.标题和内容同时进行排序: //列表先按标题相似度降序,再按内容相似度降序 同时进行俩个参数排序也可以不使用流进行直接排序排序结果:所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复