gpt4 book ai didi

java - 对树状图进行排序并没有真正起作用

转载 作者:行者123 更新时间:2023-11-30 03:47:13 28 4
gpt4 key购买 nike

我有一个基于以下结构的嵌套树状图,然后它从“2”开始继续:{具有相同的结构..

http://pastebin.com/uKwAVz5L

如您所见,它已经按“c13”子项(剧集编号)排序。但是当我在我的应用程序中使用树状图时,它显示如下:

http://i50.tinypic.com/15o9vno.png

它们甚至没有被远程排序……但我不明白为什么? :O

在我的 android 应用程序中使用它时出现同样的问题..

干杯

最佳答案

这是关于 TreeMap 的一些有值(value)的信息:

Red-Black tree based implementation of the SortedMap interface. This class guarantees that the map will be in ascending key order, sorted according to the natural order for the key's class (see Comparable), or by the comparator provided at creation time, depending on which constructor is used.

Note that the ordering maintained by a sorted map (whether or not an explicit comparator is provided) must be consistent with equals if this sorted map is to correctly implement the Map interface. (See Comparable or Comparator for a precise definition of consistent with equals.) This is so because the Map interface is defined in terms of the equals operation, but a map performs all key comparisons using its compareTo (or compare) method, so two keys that are deemed equal by this method are, from the standpoint of the sorted map, equal. The behavior of a sorted map is well-defined even if its ordering is inconsistent with equals; it just fails to obey the general contract of the Map interface.

您是否正确实现了上述方法?

Collections 也有不同的实现框架(概述是 here )。如果 TreeMap 没有提供您想要的功能,您可以实现另一个功能并根据您的需要进行修改。

关于java - 对树状图进行排序并没有真正起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14796535/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com