I am working with a java.util.Properties
object, and I generally use keySet()
to get all the keys of the properties.
I was wondering which is better keySet()
or propertyNames()
.
propertyNames()
returns the enumeration of the keys - is it because of that I generally see keySet
being used? Or is it ok to use propertyNames()
?
When looking at the sourcecode it seems, that propertyNames() considers the "defaults" where as keySet() wouldnt do that (since it is not overloaded). The defaults are a second Properties object which can optionally be passed to the constructor. So if you dont use that "defaults" argument in the constructor, keySet() is more efficient (if this matters for you), but generally more correct will be propertyNames().