Just wanted to know. What are the differences between java.util.Properties
Vs java.util.HashMap<String, String>
? Which is preferable?
There are different purpose of these two utility class. Map, or in your case, HashMap is general purpose storage object where you have unique key, and values to which they point. HashMap can have any object type as their key and any object type as their values.
java.util.Properties is, however, a special purpose map. It is developed to read/write from/to properties files. It has special methods to do so [see load(..)
]. Map does not.
So, you have different situations to use them. Places where you need properties to read, you better go with Properties. And places where you want to have lookup values stored off some logic, you go with HashMap<String, String>
.
There is no hard and fast rule, you can use HashMap<String, String>
and Properties
interchangeably. But as an engineer, use right tool for the task.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With