gpt4 book ai didi

java - 在java中,需要一些数据收集器来对字符串(如树)进行排序

转载 作者:行者123 更新时间:2023-12-01 07:09:47 24 4
gpt4 key购买 nike

我想在程序运行时将名称存储在数据结构中。当我收到一个新名称时,我希望能够尽快检查它是否已经在结构内部。

我想过使用排序堆,但不知道如何在java中处理它。

最佳答案

如果您只需要检查是否存在,则 HashSet从性能角度来看,这将是最有效的结构:

This class offers constant time performance for the basic operations (add, remove, contains and size)

如果您还需要按特定顺序(例如字母顺序)迭代名称,那么您可以使用 TreeSet相反:

This implementation provides guaranteed log(n) time cost for the basic operations (add, remove and contains).

关于java - 在java中,需要一些数据收集器来对字符串(如树)进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16791802/

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