Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.util.Properties Vs java.util.Map<String, String> [duplicate]

Just wanted to know. What are the differences between java.util.Properties Vs java.util.HashMap<String, String>? Which is preferable?

like image 342
Vaandu Avatar asked Feb 27 '12 10:02

Vaandu


1 Answers

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.

like image 75
Nishant Avatar answered Sep 28 '22 10:09

Nishant