Java's HashMap and Hashtable What is the difference HashSet and HashMap What is the difference? Use these methods to save structures need to override a number of what?

HashMap and Hashtable implement the same principles, the same function, the underlying structure is a hash table, query speed, in many cases, can be interoperable

The main difference between the two is as follows

1, Hashtable is the interface provided earlier JDK, HashMap is a new version of the interface provided by the JDK

2, Hashtable class inherits Dictionary, HashMap implements the Map interface

3, Hashtable thread-safe, HashMap non-thread-safe

4, Hashtable allowed null value, HashMap allows null value

The difference between HashSet and HashMap

1, HashSet bottom is achieved using HashMap. HashSet is easy to implement, most HashSet method is achieved by a method call HashMap, so HashSet and HashMap two collections in the realization of essentially the same.

2, HashMap the key is placed in the object HashSet, value is of type Object.

3, when calling the add method HashSet, in fact, is the addition of the target line (key-value pair), key of the row is added to the HashSet HashMap in, value of the line is a constant of type Object

Guess you like

Origin www.cnblogs.com/Yanss/p/11711825.html