问题
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