Properties in Java – can we use comma separated keys for individual values?
•
Java
I want to provide multiple keys (> 1) for a single value in the properties file of my java application A simple way is to define each key in a separate line in the properties file and define the same value for all these keys This method increases the maintainability of the attribute file Another way (which I think may be smart) is to define comma separated keys with values in a single line for example
key1,key2,key3=value
Java. util. Properties does not support this feature Has anyone made an analogy before? I did Google, but I didn't find anything
–manish
Solution
I don't know the existing solution, but it should be very simple to implement:
String key = "key1,key3",val = "value"; Map<String,String> map = new HashMap<String,String>(); for(String k : key.split(",")) map.put(k,val); System.out.println(map);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码