Performance aspect of java.util.Property vs hashmap

吃可爱长大的小学妹 提交于 2021-02-08 10:21:42

问题


I am java class and I really concern about performance. There are some methods which has Property as their input parameter and those methods are invoked several time in my execution. Will Replacing Property with Hashmap help to increase performance ? Hashmap is sufficient in my scenario.


回答1:


java.util.Properties extends java.util.Hashtable, so it is a kind of Hashtable.

Below, there are couple differences relevant for your case:

java.util.Hashtable is synchronized, but java.util.HashMap is not. If you have one-threaded application, HashMap will perform better than Hashtable.

java.util.Hashtable does not allow null keys nor values, while java.util.HashMap allows one null key and many null values.

Consider these differences for your project and take a decision.




回答2:


Properties is for special purposes, if HashMap is OK for your program - use it. HashMap also has better performance because Properties is based on Hashtable whose methods are synchronized



来源:https://stackoverflow.com/questions/30054408/performance-aspect-of-java-util-property-vs-hashmap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!