Java HashSet underlying mechanism, source code analysis, line-by-line analysis

HashSet basic description HashSet implements the Set interface HashSet is actually HashMap Can store null values, but there can only be one null HashSet does not guarantee that the elements are in order. It depends on the hash to determine the index result. There cannot be duplicate elements/objects HashSet Underlying Mechanism Description The bottom layer […]

The underlying principle of LinkedHashSet collection

1. Features of LinkedHashSet 2. LinkedHashSet principle (introduction of double linked list—–ordered) 3. TreeSet principle 1. Sort custom objects Method 1 (implement Compareable interface and rewrite comparison rules) import java.util.Objects; public class Student implements Comparable<Student>{ private String name; public int age; private double height; @Override//Rewriting of comparison rules public int compareTo(Student o) { return this.age-o.age; […]

The principle and analysis of Hashset in Java

4.Data structure 4.1 Binary Tree [Understanding] Characteristics of binary trees In a binary tree, the degree of any node must be less than or equal to 2 Node: In the tree structure, each element is called a node Degree: The number of child nodes of each node is called degree Binary tree structure diagram 4.2 […]

[Set collection in java] HashSet, LinkedHashSet, TreeSet (the most understandable version!!)

Table of Contents 1. HashSet collection 1. Characteristics of HashSet collection 2. Common methods of HashSet 2. LinkedHashSet collection Characteristics of LinkedHashSet collection 3. TreeSet collection 1. Characteristics of TreeSet collection 2.Basic use of TreeSet 4. Usage scenarios of HashSet, LinkedHashSet, and TreeSet 5. The difference between list and set collections 1. HashSet collection 1.Characteristics […]

[Set] Set collection ordered and unordered test cases: HashSet, TreeSet, LinkedHashSet (122)

Common Set collections: HashSet, TreeSe, LinkedHashSet The connection between the three: (1) HashSet and TreeSet are two typical implementations of Set, and LinkedHashSet is the implementation class of HashSet. Simply put, the performance of HashSet is always better than that of TreeSet (especially the most commonly used operations such as adding and querying elements), because […]

About the difference between HashSet and HashMap and the underlying implementation principle

Foreword: HashSet and HashMap are a question that is often asked in interviews. The difficulty lies in its underlying principles and the way it handles conflicts. The two of them are two common collection types in Java, and their main difference is how to store and access elements. Next, let’s talk about it in detail. […]

HashSet and LinkedHashSet

HashSet Introduction 1. HashSetimplements the Set interface 2. HashSet The bottom layer is actually a HashMap 3. can store null values, but there can only be one null, but the element cannot be repeated 4. HashSet does not guarantee that the elements are ordered (that is, the order of extraction and storage is inconsistent), it […]