关键区别 - 树vs HashSet
Most programming languages supportArrays. It is a data structure that is used to store multiple elements of the same data type. If there is array declared for six elements, then it cannot be used to store ten elements. Therefore, arrays are not dynamic and cannot change the size of the array once it is declared. Programming languages such asJava支持用于动态存储数据的集合。集合支持操作,例如添加元素和删除元素。有很多接口和classes在集合层次结构中。基本接口是集合接口。Setis an interface that extends the Collection interface. It does not allow duplication. The TreeSet and HashSet are two class in the Collection hierarchy and both implements the Set interface. TreeSet is a class that implements the Set interface and it is used to store unique elements in ascending order. HashSet is a class that implements the Set interface and it is used to store unique elements using the Hashing mechanism. Thekey differencebetween TreeSet and HashSet is thatTreeSet stores the elements in ascending order while the HashSet does not store the elements in ascending order.Treeset和Hashset都仅存储独特的元素。
内容
1.Overview and Key Difference
2.什么是树
3.What is a HashSet
4.Similarities Between TreeSet and HashSet
5.并排比较 - 图形与标签形式的标签
6.概括
什么是树?
Treeset类实现Navigableset接口。Navigableset接口按层次顺序扩展了排序集,集合,集合和迭代接口。树始终保持上升顺序。如果将元素插入B,A,C顺序中,则将它们存储为A,B,C。ADD(),Remove()等方法可以与TreesEt对象一起使用。添加方法可用于添加元素。删除方法用于从集合中删除元素。这些是可以与Treeset一起使用的一些方法。
根据上述程序,创建了类型树的对象。这stringdata elements are added to that object using the add method. The data inserted order is A, D, A, B, C, D. Using the iterator, the stored values are printed to the screen. The output is A, B, C, D. Even though, there are two A letters and two D letters, the output displays the one A and one D each. Therefore, the TreeSet stores unique elements. There is no particular insertion order but when observing the output, it can be seen that the TreeSet maintains the ascending order of the elements.
什么是哈希集?
HashSet类扩展了套抽象class that implements Set Interface. The Set interface inherits Collection and Iterable interfaces in hierarchical order. In HashSet, there is no guarantee that the elements will maintain the ascending order and the inserted order. If the inserted order was A, B, C then the values might store as C, A, B. Storing order can also be A, B, C but there is no guarantee that the inserted order or ascending order is maintained.
According to the above program, an object of type HashSet is created. The string data elements are added to that object using the add method. The data inserted order is L, R, M, M, R, L. Using the iterator, the stored values are printed to the screen. The output is R L M. Even though, there are two L, R and M letters from each, only one letter from each is displayed. Therefore, the HashSet stores unique elements. When observing the output, it can be seen that there is no ascending order or the inserted order is maintained.
树和哈希集之间有什么相似之处?
- Both TreeSet and HashSet are classes belong to the collection hierarchy.
- Both TreeSet and HashSet stores only unique elements.
- Both TreeSet and HashSet can be used to store and manipulate many elements.
- Both TreeSet and HashSet do not maintain the inserted order.
What is the Difference Between TreeSet and HashSet?
TreeSet vs HashSet |
|
TreeTET是集合层次结构中的一类,用于按升序存储唯一的元素。 | HashSet is a class in the collection hierarchy that is used to store unique elements using the Hashing mechanism. |
Element Storing | |
Treeset按升序存储元素。 | 标签不能以升序存储元素。 |
概括– TreeSetvs HashSet
在编程中,需要动态存储数据元素。诸如Java之类的编程语言支持收集以实现此任务。集合层次结构中有许多接口和类。Treeset和Hashset是集合层次结构中的两个类。两者都实现了集合接口。Treeset是实现集合接口的类,用于按升序存储唯一的元素。Hashset是实现集合接口的类,用于使用哈希机制来存储唯一的元素。树和标签之间的区别在于,树以升序存储元素,而主题集则不会按升序存储元素。本文讨论了Treeset和Hashset之间的区别。
Reference:
1.“TreeSet in Java – javatpoint.”JavaPoint.Available here
2.“爪哇 - javatpoint。”JavaPoint.Available here
发表评论