博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
为什么Java中没有SortedList?
阅读量:2380 次
发布时间:2019-05-10

本文共 3270 字,大约阅读时间需要 10 分钟。

本文翻译自:

In Java there are the SortedSet and SortedMap interfaces. 在Java中,有SortedSetSortedMap接口。 Both belong to Java's standard Collections framework and provide a sorted way to access the elements. 两者都属于Java的标准集合框架,并提供了一种访问元素的排序方式。

However, in my understanding there is no SortedList in Java. 但是,根据我的理解,Java中没有SortedList You can use java.util.Collections.sort() to sort a list. 您可以使用java.util.Collections.sort()对列表进行排序。

Any idea why it is designed like that? 知道为什么它的设计是这样的吗?


#1楼

参考:


#2楼

First line in the List API says it is an ordered collection (also known as a sequence). List API中的第一行表示它是一个有序集合(也称为序列)。 If you sort the list you can't maintain the order, so there is no TreeList in Java. 如果对列表进行排序,则无法维护顺序,因此Java中没有TreeList。

As API says Java List got inspired from Sequence and see the sequence properties ) 正如API所说,Java List受到了Sequence的启发,并且看到了序列属性 )

It doesn't mean that you can't sort the list, but Java strict to his definition and doesn't provide sorted versions of lists by default. 这并不意味着您不能对列表进行排序,而是Java严格按照他的定义,并且默认情况下不提供列表的排序版本。


#3楼

Consider using . 考虑使用 。 It's an enhanced JDK's TreeSet that provides access to element by index and finding the index of an element without iteration or hidden underlying lists that back up the tree. 它是一个增强的JDK TreeSet,它通过索引提供对元素的访问,并查找没有迭代的元素索引或者备份树的隐藏底层列表。 The algorithm is based on updating weights of changing nodes every time there is a change. 该算法基于每次改变时更新节点的权重。


#4楼

JavaFX SortedList JavaFX SortedList

Though it took a while, Java 8 does have a sorted List . 虽然花了一段时间,但Java 8确实有一个排序List

As you can see in the javadocs, it is part of the collections, intended to provide a sorted view on an ObservableList. 正如您在javadocs中看到的,它是集合的一部分,旨在提供ObservableList的排序视图。

Update: Note that with Java 11, the JavaFX toolkit has moved outside the JDK and is now a separate library. 更新:请注意,对于Java 11,JavaFX工具包已移出JDK,现在是一个单独的库。 JavaFX 11 is available as a downloadable SDK or from MavenCentral. JavaFX 11可作为可下载的SDK或MavenCentral提供。 See 请参阅


#5楼

For any newcomers, as of April 2015, Android now has a class in the support library, designed specifically to work with RecyclerView . 对于任何新手,截至2015年4月,Android现在在支持库中有一个类,专门设计用于与RecyclerView Here's the about it. 这是关于它的 。


#6楼

Set and Map are non-linear data structure. Set和Map是非线性数据结构。 List is linear data structure. 列表是线性数据结构。


The tree data structure SortedSet and SortedMap interfaces implements TreeSet and TreeMap respectively using used implementation algorithm. 树数据结构SortedSetSortedMap接口分别使用使用的实现算法实现TreeSetTreeMap So it ensure that there are no duplicated items (or keys in case of Map ). 因此,它确保没有重复的项目(或Map情况下的键)。

  • List is already maintains an ordered collection and index-based data structure, trees are no index-based data structures. List已经维护了一个有序的集合和基于索引的数据结构,树不是基于索引的数据结构。
  • Tree by definition cannot contain duplicates. 根据定义, Tree不能包含重复项。
  • In List we can have duplicates, so there is no TreeList (ie no SortedList ). List我们可以有重复项,因此没有TreeList (即没有SortedList )。
  • List maintains elements in insertion order. List按插入顺序维护元素。 So if we want to sort the list we have to use java.util.Collections.sort() . 因此,如果我们要对列表进行排序,我们必须使用java.util.Collections.sort() It sorts the specified list into ascending order, according to the natural ordering of its elements. 它根据元素的自然顺序将指定列表按升序排序。

转载地址:http://dyexb.baihongyu.com/

你可能感兴趣的文章
ffmpeg系列:使用ffmpeg转换为RGB数据并缩放视频
查看>>
Vmware虚拟机设置固定IP地址
查看>>
能Ping通外网但就是不能打开所有网页的解决办法
查看>>
windows7配置虚拟AP的脚本
查看>>
融合广播或成电台发展新方向 进军大数据
查看>>
看“大数据”如何帮我们寻找爱情
查看>>
国家统计局:利用大数据做好网购统计
查看>>
大数据会带来越来越细的标准
查看>>
你不知道的天猫“双十一”:大数据成为新驱动力
查看>>
北京开放政府信息资源 “大数据”供社会化利用
查看>>
大数据挖掘变革 美赛达软硬云引领车联网商业蓝海
查看>>
停车费上涨需要公开“大数据”
查看>>
大数据和互联网思维或能有效缓解交通拥堵
查看>>
助力大数据开发 IBM收购DBaaS提供商Cloudant
查看>>
大数据驱动电信运营商转型
查看>>
玩转大数据 运动员如何用科技提升成绩
查看>>
广发银行试水大数据 “精细服务”现雏形
查看>>
大数据让社区生活更方便
查看>>
借助互联网大数据打假
查看>>
东信北邮大数据项目获2014中国通信学会科学技术一等奖
查看>>