What is the diff between a TreeMap vs. HashMap?
来源:互联网 发布:网络的发展与未来二课 编辑:程序博客网 时间:2024/06/07 15:14
Thelargest difference between the two is the underlying structure used in theimplementation.
HashMapsuse an array and a hashing function to store elements. When you try to insert ordelete an item in the array the hashing function converts the key into an indexon the array where the object is/should be stored (ignoring conflicts). Whilehashmaps are generally very fast because they don't need to iterate over largeamounts of data, they slow down when they're filled because they need to copyall the key/values into a new array.
TreeMapsstore a the data in a sorted tree structure. While this means that they'llnever have to allocate more space and copy over to it, operations require thatpart of the data already stored be iterated over. Sometimes changing largeamounts of the structure.
Out ofthe two Hashmaps will generally have better performance when you don't needsorting.
Insertiontime of HashMap is O(1) if the hash code disperses keys appropriately.
Insertion time of TreeMap is O(log(n)).- What is the diff between a TreeMap vs. HashMap?
- What is the difference between a thread and a process?
- What is the difference between a definition and a declaration?
- What is the difference between a process and a thread?
- What is the difference between an EXE and a DLL?
- What is the difference between a Generative and Discriminative Algorithm?
- What is the difference between GenericServlet, HttpServlet and a Servlet?
- What is the difference between a = a * (2^3) and a = a << 3?
- What is the difference between a processor, a chip, a socket, and a core?
- What is the difference between a theorem, a lemma, and a corollary?
- What Is the Difference Between a Block, a Proc, and a Lambda in Ruby
- What is the difference between a URI, a URL and a URN
- What is the Difference Between Proxy Types?
- What is the difference between test, [ and [[ ?
- What is the difference between a von Neumann architecture and a Harvard architecture?
- What is the difference between a pack slip and a pick slip?
- What is the difference between a Bayesian network and a Naive Bayes classifier?
- In SQL, what is the difference between a left join and a left outer join?
- [转]delphi的构造函数和析构函数
- 使用ngrok让微信公众平台通过80端口访问本机
- jQuery [jQuery视频教程--->Jq网页开发精解04] 设计列表 文字滚动 图片按比例显示
- oracle CMD导入dmp文件的语句
- Linux下查看系统版本号信息的方法
- What is the diff between a TreeMap vs. HashMap?
- Tomcat7 内存溢出
- CoreData 快速集成 神奇输入法FleksySDK
- 深入浅出Java 重定向和请求转发的区别
- 人脸识别经典算法二:LBP方法
- HDOJ 4005 The war
- Java利用TCP进行文件的传输
- 性能loadrunner--web_custom_request和web_submit_data
- PHP自动重命名文件算法